MongoDB Atlas-backed thread/session persistence for VRSEN Agency Swarm.
Project description
agency-swarm-mongodb
MongoDB Atlas–backed thread/session persistence for VRSEN Agency Swarm.
Drop-in load_threads_callback / save_threads_callback for the Agency class — persist
entire conversations to MongoDB and restore them across application restarts.
Why
Agency Swarm persists conversations through two Agency hooks but ships no database
backend (only a file-based example). MongoThreadStore is that backend: one document per
chat_id, idempotent upserts, optional TTL expiry — backed by MongoDB or Atlas.
Install
pip install agency-swarm-mongodb
Usage
from agency_swarm import Agency, Agent
from agency_swarm_mongodb import MongoThreadStore
store = MongoThreadStore("mongodb+srv://...", database_name="agency_swarm")
load_cb, save_cb = store.as_callbacks("user-123") # chat_id captured in the closures
agency = Agency(
Agent(name="Assistant", instructions="You are helpful."),
load_threads_callback=load_cb,
save_threads_callback=save_cb,
)
The store matches the Agency Swarm callback signatures exactly:
load_threads_callback() -> list[dict] and save_threads_callback(messages: list[dict]) -> None.
Options
| Arg | Default | Purpose |
|---|---|---|
connection_string |
— | MongoDB / Atlas URI (required unless client given) |
database_name |
agency_swarm |
Database name |
collection_name |
threads |
Collection name |
ttl_seconds |
None |
If set, TTL index on updated_at auto-expires idle chats |
client |
None |
Bring your own MongoClient (then appName is not overwritten) |
Document shape
{
"_id": "user-123", // chat_id
"messages": [ /* full flat list, exactly as Agency Swarm emits */ ],
"message_count": 12,
"updated_at": { "$date": "..." }
}
Demos
demo/custom_persistence_mongo.py— Mongo-backed mirror of Agency Swarm'scustom_persistence.py: run a turn, simulate a restart, verify recall.demo/agent_demo.py— a Gemini agent whose threads persist to Atlas, plus an Atlas Vector Search staffing tool over a team directory (Voyage 3.5 embeddings).
pip install -e ".[demo]"
pip install "openai-agents[litellm]" "litellm[proxy]"
# demo/.env: ATLAS_URI, VOYAGE_API_KEY, GEMINI_API_KEY
python demo/agent_demo.py
Conventions
- Connection
appName:devrel-integ-agencyswarm-python(server-side attribution). - Driver handshake metadata:
agency-swarm-mongodb(distinct from appName).
Tests
pip install -e ".[dev]"
pytest -q # 9 tests, mongomock — no infra required
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 agency_swarm_mongodb-0.1.0.tar.gz.
File metadata
- Download URL: agency_swarm_mongodb-0.1.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4958579c06f620ea8a58f797c1092ed0b5475a97d28a62dd58ae44312a2dd976
|
|
| MD5 |
90d3749c1ae65b0a5a076236ee511bd6
|
|
| BLAKE2b-256 |
da867de79582ce7ec1cdeeb32c1510308b3100cafe70aef9876ca21e7ea4e778
|
Provenance
The following attestation bundles were made for agency_swarm_mongodb-0.1.0.tar.gz:
Publisher:
release.yml on mongodb-developer/agency-swarm-mongodb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agency_swarm_mongodb-0.1.0.tar.gz -
Subject digest:
4958579c06f620ea8a58f797c1092ed0b5475a97d28a62dd58ae44312a2dd976 - Sigstore transparency entry: 1702516797
- Sigstore integration time:
-
Permalink:
mongodb-developer/agency-swarm-mongodb@8c122cd63118226e07d84e2c0722ee370dc62bd1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mongodb-developer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c122cd63118226e07d84e2c0722ee370dc62bd1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file agency_swarm_mongodb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agency_swarm_mongodb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9edc4653d5c2e95f17910cc2b0fff57488ce449c1c5447bde131d544d5c26fec
|
|
| MD5 |
047f9d67c466c8192302a54135157f91
|
|
| BLAKE2b-256 |
e860db97e4d76be6942e82530df2f46ed19affb8e9b5e8439fa8926a4d13c8c4
|
Provenance
The following attestation bundles were made for agency_swarm_mongodb-0.1.0-py3-none-any.whl:
Publisher:
release.yml on mongodb-developer/agency-swarm-mongodb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agency_swarm_mongodb-0.1.0-py3-none-any.whl -
Subject digest:
9edc4653d5c2e95f17910cc2b0fff57488ce449c1c5447bde131d544d5c26fec - Sigstore transparency entry: 1702516831
- Sigstore integration time:
-
Permalink:
mongodb-developer/agency-swarm-mongodb@8c122cd63118226e07d84e2c0722ee370dc62bd1 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mongodb-developer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@8c122cd63118226e07d84e2c0722ee370dc62bd1 -
Trigger Event:
push
-
Statement type: