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
Metadata
Release files for strands_session_mongodb 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| strands_session_mongodb-0.2.0.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| strands_session_mongodb-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.5 kB
Release files / strands_session_mongodb-0.2.0.tar.gz
| Download URL | strands_session_mongodb-0.2.0.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42af4764c5ab1543194346dbb0970a5d3a1b11095e2826ee45a09ce1f477dc9c
|
|
BLAKE2b-256 checksum How to use checksums |
d801fcc07867f08846cf03e132127a8323b8b66c61c4aa2349aa697681c85c15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / strands_session_mongodb-0.2.0-py3-none-any.whl
| Download URL | strands_session_mongodb-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ae490230eefbc2e13730b8f1f83f16661ba1ac83fb2998921d133250744036b
|
|
BLAKE2b-256 checksum How to use checksums |
0132837c131fd5bf01b123a828504fa88f9243edb42e35597733fc8331275f27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Security for strands_session_mongodb 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.