A structured guide for AI agents working in crewai-mongodb-memory: how to build and test, where
key files live, and the MongoDB-specific rules to follow.
MongoDBStorageBackend — a full implementation of CrewAI's Unified Memory
StorageBackend
protocol, backed by MongoDB Atlas (with $vectorSearch for semantic recall). It plugs into
crewai.memory.unified_memory.Memory(storage=...).
# Install (editable) + dev deps
pip install -e ".[dev]"
# Run the acceptance test suite (offline via mongomock; Atlas vector test auto-skips)
pytest -q
# Run the full suite incl. the live Atlas $vectorSearch test
export ATLAS_URI="mongodb+srv://…"
export VOYAGE_API_KEY="pa-…"
pytest -q
# Run the demos
pip install -r demo/requirements.txt
python demo/memory_demo.py # corpus load + scope inspection + vector recall
python demo/agent_demo.py # Gemini agent w/ long-term preference memory (needs GEMINI_API_KEY)src/crewai_mongodb_memory/backend.py—MongoDBStorageBackend(the 8 protocol methods).src/crewai_mongodb_memory/embeddings.py— Voyage 3.5 helper (embed_text).demo/memory_demo.py,demo/agent_demo.py,demo/requirements.txt.tests/test_acceptance.py— one test per acceptance criterion (CRUD/scope/vector + appName + driver-info + protocol membership).EDD.md— the MongoDB data model (source of truth for schema).PLAN.md— the 7-phase integration plan.
| Name | Required | Description |
|---|---|---|
ATLAS_URI |
for search() / demos |
Atlas connection string |
VOYAGE_API_KEY |
when embedding text | Voyage AI key for voyage-3.5 |
GEMINI_API_KEY |
agent demo only | Powers the Gemini model via CrewAI |
- The package owns its
MongoClient— built from a connection string, never passed in. appNameis fixed todevrel-integ-crewai-pythonand the driver-info handshake (crewai-mongodb-memory) is attached; both are non-overridable (callerappname/appName/driverkwargs are stripped).- Embeddings use Voyage AI 3.5 (
voyage-3.5, 1024-dim). The backend is embedding source-agnostic at the protocol boundary:search()receives aquery_embeddingvector directly — no silent fallback. embeddingisexclude=Trueon CrewAI'sMemoryRecord; persist it explicitly (_to_doc).- Scope-prefix filtering inside
$vectorSearchuses the precomputedscope_ancestorsarray, because vector-search filters do not support$regex. Keepscope_ancestorsin sync withscopeon every write.
Use the official MongoDB agent skills from https://github.com/mongodb/agent-skills whenever the task is MongoDB-specific and a matching skill exists.
Use EDD.md as the source of truth for the MongoDB data model in this repository.
Consult EDD.md before making changes that touch:
- MongoDB collections, document structure, or field names
- Code paths that read or write database records (
backend.py) - The
StorageBackendprotocol method ↔ MongoDB operation mapping - Index definitions (ordinary, multikey, Atlas Vector Search)
- Schema documentation, Mermaid diagrams, or entity modeling discussions