MongoDB session manager (storage backend) for Strands Agents — persists sessions, agent state, and messages
Project description
strands-session-mongodb
MongoDB session manager (storage backend) for Strands Agents. Persists an agent's sessions, agent state, conversation-manager state, and messages to MongoDB so conversations resume across runs.
Part of the strands-agents-session family — it implements the base SessionStorage interface, so all the Strands session-repository logic (message indexing, restore, removed_message_count offsetting, tool-use repair) comes from the core.
Storage only, by design. Message pruning in Strands is a
ConversationManagerconcern, decoupled from storage. This package does not prune.
Installation
pip install strands-session-mongodb
# or, via the family's extra:
pip install "strands-agents-session[mongodb]"
Requires Python 3.10+ and a reachable MongoDB (local, Atlas, or self-hosted).
Quick start
from strands import Agent
from strands_session_mongodb import MongoDBSessionManager
session_manager = MongoDBSessionManager(
session_id="user-123",
connection_string="mongodb://127.0.0.1:27017/",
)
agent = Agent(session_manager=session_manager)
agent("Hi, I'm Kamal")
agent("What's my name?") # remembers within the session
Next run, same session_id → the agent restores its full history and state from MongoDB.
API
MongoDBSessionManager(session_id, *, connection_string="mongodb://127.0.0.1:27017/", database_name="strands_sessions", collection_name="sessions", client=None, ttl_seconds=None)
| Parameter | Description |
|---|---|
session_id |
Session identifier |
connection_string |
MongoDB URI (local, Atlas mongodb+srv://…, etc.) |
database_name |
Database (default strands_sessions) |
collection_name |
Collection (default sessions) |
client |
Optional pre-built pymongo.MongoClient to reuse |
ttl_seconds |
If set, adds a TTL index so documents expire automatically |
Data model
A single collection; each document has a pk + sk (compound-indexed, unique) and a data field with the serialized payload:
| Item | pk | sk |
|---|---|---|
| Session | SESSION#<session_id> |
META |
| Agent | SESSION#<session_id> |
AGENT#<agent_id> |
| Message | SESSION#<session_id>#AGENT#<agent_id> |
MSG#<zero-padded id> |
The (pk, sk) index gives ordered range scans, so list_messages(offset, limit) is a simple indexed find(...).sort(sk).limit(...) — matching the removed_message_count offset semantics Strands relies on.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strands_session_mongodb-0.2.0.tar.gz.
File metadata
- Download URL: strands_session_mongodb-0.2.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42af4764c5ab1543194346dbb0970a5d3a1b11095e2826ee45a09ce1f477dc9c
|
|
| MD5 |
cc891ec3240f78453ad76e4418f5ce67
|
|
| BLAKE2b-256 |
d801fcc07867f08846cf03e132127a8323b8b66c61c4aa2349aa697681c85c15
|
File details
Details for the file strands_session_mongodb-0.2.0-py3-none-any.whl.
File metadata
- Download URL: strands_session_mongodb-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ae490230eefbc2e13730b8f1f83f16661ba1ac83fb2998921d133250744036b
|
|
| MD5 |
8a11bdd02d5d37710edd35d6d1675648
|
|
| BLAKE2b-256 |
0132837c131fd5bf01b123a828504fa88f9243edb42e35597733fc8331275f27
|