MongoDB
agentscope-extensions-mongodb provides full-stack MongoDB distributed storage — ideal for deployments that already run MongoDB or prefer a document-oriented backend for agent runtime data.
Dependency
One-Line Setup
/mydb), that database is used instead of the default agentscope.
Components Provided
1. MongoAgentStateStore
Agent session state persisted to MongoDB. Each session is a single document with a compound_id of {user, session}. State keys are stored inside a states sub-document (via dot notation), keeping them isolated from reserved top-level fields.
- Single value: stored at
states.<key>as a BSON sub-document; version atversions.<key>. - List value: stored at
states.<key>as a BSON array; content hash athashes.<key>for incremental-append optimization. - TTL: 30-day expiry on
_updated_at(sparse index), aligned with snapshot TTL.
2. MongoBaseStore (BaseStore)
Workspace filesystem KV storage forRemoteFilesystemSpec. Uses prefix-matching via range queries on a compound (namespace, key) index — consistent with InMemoryStore and PostgresBaseStore.
- Namespace paths use
\u001F(ASCII Unit Separator) as the segment delimiter, with a trailing separator enabling prefix matching. put/putIfVersionsupport optimistic concurrency via aversionfield.
3. MongoSnapshotSpec
Sandbox snapshots stored as BSON Binary in a collection with a 30-day TTL index oncreatedAt. Aligned with the session TTL so snapshots outlive their sessions.
BSON document size limit is 16 MB; snapshots are capped at 15 MB. For larger workspaces, consider a mixed store (MongoDB for state/lock, OSS for snapshots).
4. MongoSandboxExecutionGuard
Distributed lock using a dedicated MongoDB collection with a TTL index onexpiresAt. Each acquisition generates a random UUID token for safe renewal and release — two guard instances in the same JVM cannot accidentally release each other’s locks.
lockTimeoutbounds acquisition wait only;leaseTtlcontrols the lock document lifetime.- A background watchdog renews the lease every
leaseTtl / 3using a 2-thread pool. - The guard implements
AutoCloseableand is shut down byMongoDistributedStore.close().
Collections and TTL
All collection names are centralised in
MongoConstants and can be overridden per component.