Skip to main content
Back to timeline
MongoDB | BlogSource publication:

Strands agents stop depending on local state: MongoDB's open-source package puts sessions and long-term memory in the database

Synopsis

MongoDB released strands-mongodb, an open-source Python package that connects AWS's Strands agent framework to MongoDB so sessions and long-term memory no longer live inside a single process. The Strands Harness SDK previously shipped with local-file and Amazon S3 backends, so a new process could not see the previous turn's state. With the integration, each invocation reloads a session by its ID from MongoDB and continues, while long-term memories are kept in MongoDBMemoryStore and can be retrieved by meaning through Atlas Vector Search.

AI-generated editorial illustration: Persistent Sessions and Memory for Strands with MongoDB

Interpretation

A Strands agent's session state and long-term memory can now sit in MongoDB rather than on the machine handling one request. The Strands Harness SDK originally shipped with local-file and Amazon S3 storage backends, tying state to a single process so the next invocation on another instance could not see the previous turn. In an AWS Lambda deployment, two Lambda instances serve consecutive turns of the same session, and both read and write the session through MongoDBStorage and long-term memory through MongoDBMemoryStore, neither depending on the other's local state.

Wiring takes three agent parameters, and the SDK connects storage, session management and memory management to MongoDB itself. The storage= parameter makes MongoDB the default backend for five SDK subsystems, including sessions, context offloading and transcripts; session_manager= uses SnapshotSessionManager to save and restore the conversation by session ID; memory_manager= gives the model tools to search and save memory. Memory is written as plain text and searched as plain text, with Atlas Automated Embedding generating and updating vectors in the background using voyage-4-lite by default, and each query embedded before $vectorSearch runs, so no batch job keeps vectors in step with the text.

Perspective

The demonstrated setting is a Strands agent deployed in disposable environments such as AWS Lambda, with different instances handling consecutive turns of the same session; MongoDBStorage works on any MongoDB deployment, while memory search with Automated Embedding requires a MongoDB Atlas cluster with a registered embedding model.

Tenant isolation is enforced by the package rather than the server, so where a tenant boundary is also a compliance boundary, each tenant needs its own database or collection with restricted credentials. Memory deduplication uses a content hash to turn a repeated extraction into a no-op, keeping the original timestamp and expiry. Retrieval automatically selects among Vector Search, Atlas Search text search and $rankFusion hybrid search according to the deployment.