MongoDB Atlas-backed StorageBackend (memory store) for CrewAI's Unified Memory System.
Project description
crewai-mongodb-memory — MongoDB Atlas memory backend for CrewAI
MongoDB Atlas integration for CrewAI providing the Memory Store (MS) capability:
MongoDBStorageBackend, a full implementation of CrewAI's Unified Memory StorageBackend
protocol that makes Atlas the long-term memory layer for CrewAI agents and crews — including
semantic recall via Atlas Vector Search.
- appName:
devrel-integ-crewai-python - Embeddings: Voyage AI 3.5 (
voyage-3.5, 1024-dim) - Extension point:
crewai.memory.storage.backend.StorageBackend - Plan: see
PLAN.md— the per-integration 7-phase plan. - Schema: see
EDD.md— the MongoDB data model (entities, indexes, diagram).
Capabilities
-
Drop-in
StorageBackendforcrewai.memory.unified_memory.Memory(storage=...)— implements all 8 protocol methods (save,search,delete,update,get_record,list_records,get_scope_info,list_scopes). -
Semantic recall via Atlas
$vectorSearch, prefiltered by hierarchicalscope,categories, and arbitrarymetadata— the surface the upstreamRedisStorageBackend(PR #5919) explicitly leaves unimplemented. -
Hierarchical scopes (
/crew/team/user) with prefix queries over descendants. -
Durable short-term conversation memory via
ConversationMemory— persists each chat turn to Atlas and replays the last N turns into the agent's context. CrewAI builds a fresh Crew perkickoff()with no shared state, so this keeps a multi-turn thread coherent and lets it survive a process restart. Stored in its ownconversationscollection (kept out of the vector index), without embeddings (replay is recency/order based, not semantic), using the MongoDB bucket pattern (an array of turns per document) for cheap append + range reads. -
Own-the-client design: appName + driver-info handshake always present, non-overridable.
Architecture Overview
The backend stores one MongoDB document per MemoryRecord (keyed by the record id) and
maps the protocol onto MongoDB:
- Collection
memories— one document per memory record. - Indexes —
scope,categories,created_at, plus an Atlas Vector Search index overembedding(numDimensions: 1024, cosine) withfilterpathsscope_ancestors+categories. - Queries —
replace_oneupserts for writes;$vectorSearchfor semanticsearch(). - Scope-prefix filtering inside
$vectorSearchuses a precomputedscope_ancestorsarray (vector-search filters don't support$regex).
See EDD.md for the full schema contract.
Prerequisites
- Python 3.10+
- A MongoDB connection: local
mongodb://localhost:27017works for CRUD/scope operations; MongoDB Atlas is required forsearch()(Vector Search). VOYAGE_API_KEYif you embed query/document text withvoyage-3.5(the demos do).GEMINI_API_KEYfor the agentic demo (demo/agent_demo.py).
Quick Start
# 1. Install the package
pip install crewai-mongodb-memory # or, from this repo: pip install -e ".[dev]"
# 2. Use it as a CrewAI memory backend
python - <<'PY'
from crewai.memory.unified_memory import Memory
from crewai_mongodb_memory import MongoDBStorageBackend
backend = MongoDBStorageBackend("mongodb+srv://…") # owns its own client
memory = Memory(storage=backend) # drop-in Unified Memory backend
PY
# 3. Run the demos (see demo/requirements.txt)
pip install -r demo/requirements.txt
export ATLAS_URI="<your Atlas connection string>"
export VOYAGE_API_KEY="<your Voyage key>"
export GEMINI_API_KEY="<your Gemini key>" # agent demo only
python demo/memory_demo.py # vector recall over the canonical corpus
python demo/agent_demo.py # Gemini agent with long-term preference memory
python demo/cli_demo.py # interactive REPL: chat + /remember /recall /scope
# 4. Run the acceptance tests (offline via mongomock; Atlas test auto-skips without creds)
pytest -q
Expected: memory_demo.py prints scope info + top-k semantic matches; agent_demo.py
shows a brand-new crew recalling preferences stored in a previous session; the test suite
reports 9 passed (or 8 passed + 1 skipped without Atlas creds).
Environment variables
| Name | Required | Example | Description |
|---|---|---|---|
ATLAS_URI |
for search() / demos |
mongodb+srv://… |
Atlas connection string |
VOYAGE_API_KEY |
when embedding text | pa-… |
Voyage AI key for voyage-3.5 |
GEMINI_API_KEY |
agent demo only | AIza… |
Powers the Gemini model via CrewAI |
Project structure
src/crewai_mongodb_memory/ # MongoDBStorageBackend + Voyage embedding helper
demo/ # memory_demo.py, agent_demo.py, requirements.txt
tests/ # acceptance tests (CRUD/scope/vector + appName + driver-info)
EDD.md # MongoDB schema contract (entities, indexes, Mermaid diagram)
AGENTS.md # guide for AI coding agents
PLAN.md # the per-integration 7-phase plan
Why MongoDB?
- MongoDB Atlas Vector Search — semantic recall over agent memory, natively.
- Atlas Search (full-text)
- One operational database for memory + application data — no extra vector store to run.
Additional resources
- Outreach:
outreach/blog.md,outreach/social.md - Upstream protocol:
StorageBackend· precedent PR #5919 - Package: https://pypi.org/project/crewai-mongodb-memory/ (pending publish)
Status
See PLAN.md for the current phase and memory-bank/progress.md for the board.
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 crewai_mongodb_memory-0.1.0.tar.gz.
File metadata
- Download URL: crewai_mongodb_memory-0.1.0.tar.gz
- Upload date:
- Size: 24.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
766299aaf194fdba57286e5769b502bca25334d39ab91ad51368e8c567bae673
|
|
| MD5 |
88ba032c7b47bffe3731455e1cc6f07f
|
|
| BLAKE2b-256 |
bc4c55c31a29d0679443ba42609bbec56240a281bf629cbcd6dbbb2caaa94bf3
|
Provenance
The following attestation bundles were made for crewai_mongodb_memory-0.1.0.tar.gz:
Publisher:
release.yml on mongodb-developer/crewai-mongodb-memory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crewai_mongodb_memory-0.1.0.tar.gz -
Subject digest:
766299aaf194fdba57286e5769b502bca25334d39ab91ad51368e8c567bae673 - Sigstore transparency entry: 2128473119
- Sigstore integration time:
-
Permalink:
mongodb-developer/crewai-mongodb-memory@4b5b4a1721bf54d6e6d9a3a70523a39f846a77bf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mongodb-developer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b5b4a1721bf54d6e6d9a3a70523a39f846a77bf -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file crewai_mongodb_memory-0.1.0-py3-none-any.whl.
File metadata
- Download URL: crewai_mongodb_memory-0.1.0-py3-none-any.whl
- Upload date:
- Size: 15.3 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 |
76b36a96f3ef0f99e6ac7aa49b7902e4247f1607500a2ed5f94d5cbdb2751723
|
|
| MD5 |
a80d262b6253f09d56db0a124ff4d9a1
|
|
| BLAKE2b-256 |
c71d8654cdda764148c70029710286010266d6efe4c08d4d84c2d8b1b164aa3b
|
Provenance
The following attestation bundles were made for crewai_mongodb_memory-0.1.0-py3-none-any.whl:
Publisher:
release.yml on mongodb-developer/crewai-mongodb-memory
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
crewai_mongodb_memory-0.1.0-py3-none-any.whl -
Subject digest:
76b36a96f3ef0f99e6ac7aa49b7902e4247f1607500a2ed5f94d5cbdb2751723 - Sigstore transparency entry: 2128473150
- Sigstore integration time:
-
Permalink:
mongodb-developer/crewai-mongodb-memory@4b5b4a1721bf54d6e6d9a3a70523a39f846a77bf -
Branch / Tag:
refs/heads/main - Owner: https://github.com/mongodb-developer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4b5b4a1721bf54d6e6d9a3a70523a39f846a77bf -
Trigger Event:
workflow_dispatch
-
Statement type: