Skip to main content

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's custom_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

agency_swarm_mongodb-0.1.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

agency_swarm_mongodb-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

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

Hashes for agency_swarm_mongodb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4958579c06f620ea8a58f797c1092ed0b5475a97d28a62dd58ae44312a2dd976
MD5 90d3749c1ae65b0a5a076236ee511bd6
BLAKE2b-256 da867de79582ce7ec1cdeeb32c1510308b3100cafe70aef9876ca21e7ea4e778

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file agency_swarm_mongodb-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agency_swarm_mongodb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9edc4653d5c2e95f17910cc2b0fff57488ce449c1c5447bde131d544d5c26fec
MD5 047f9d67c466c8192302a54135157f91
BLAKE2b-256 e860db97e4d76be6942e82530df2f46ed19affb8e9b5e8439fa8926a4d13c8c4

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page