type: mem0), giving your agents cloud-managed semantic search and cross-session persistence — all without writing any code.
Overview
In this guide, you’ll:- Set up ChatDev with the Mem0 memory store
- Configure agents with persistent memory using YAML
- Enable automatic memory retrieval and storage across conversations
- Leverage cross-session persistence for personalized multi-agent interactions
Prerequisites
- Python 3.12+
- uv — Python package manager
- Node.js 18+ and npm — only needed if using the web console
- A Mem0 API key from app.mem0.ai
- An OpenAI API key (or another LLM provider supported by ChatDev)
Setup and Configuration
Install ChatDev and its dependencies (includesmem0ai):
.env file:
Get your Mem0 API key from Mem0 Platform.
Configure Mem0 Memory Store
In your ChatDev workflow YAML, add a Mem0 memory store in thememory section:
Attach Memory to an Agent
Reference the memory store in your agent node’smemories list:
read: true— Agent retrieves relevant memories before generating a responsewrite: true— Agent stores new memories from user input after each interactiontop_k— Number of memories to retrieve per querysimilarity_threshold— Minimum relevance score for retrieved memories. Set to-1.0to return all results regardless of scoreretrieve_stage— When to retrieve memories. Options:pre_gen_thinking(before generation),gen(during generation),post_gen_thinking(after generation),finished(after completion)
Full Example Workflow
Here’s a complete workflow YAML that creates a memory-backed conversational agent:http://localhost:5173, create a new workflow, and paste your YAML configuration into the editor. The web console provides a visual chat interface for interacting with your memory-backed agents.
How It Works
When an agent with Mem0 memory receives input, the following cycle runs automatically: 1. Retrieve — Before generating a response, ChatDev queries Mem0 with the user’s input using semantic search. Relevant memories are injected into the agent’s context in this format:===== Related Memories ===== — the agent needs to know how to use this injected context.
2. Generate — The agent produces a response using the retrieved memories as additional context.
3. Store — After generation, the user’s input is sent to Mem0 via client.add(). Mem0’s extraction model automatically identifies and stores facts, preferences, and key information. Only user input is stored — agent output is excluded to keep memories clean.
Memories persist in Mem0’s cloud across all sessions. The next time the same user_id or agent_id is used, previous memories are automatically retrieved.
Dual-Scope Memory (User + Agent)
When bothuser_id and agent_id are configured, Mem0 uses an OR filter to search across both scopes in a single query:
Configuration Reference
Memory Store Config
| Field | Required | Description |
|---|---|---|
api_key | Yes | Mem0 API key from app.mem0.ai |
user_id | No | Scope memories to a specific user |
agent_id | No | Scope memories to a specific agent |
Memory Attachment Config
| Field | Default | Description |
|---|---|---|
top_k | 3 | Number of memories to retrieve |
similarity_threshold | -1.0 (disabled) | Minimum relevance score. Set a value between 0.0 and 1.0 to filter low-relevance results. Default (-1.0) returns all matches without filtering |
retrieve_stage | ["gen"] | When to retrieve: pre_gen_thinking, gen, post_gen_thinking, or finished |
read | true | Whether the agent retrieves memories |
write | true | Whether the agent stores new memories |
Tips and Common Pitfalls
Indexing delay — Freshly stored memories may take a few seconds to become searchable. If a memory isn’t retrieved immediately after being stored, wait a moment and try again.
- No memories returned on first run — This is expected. Memories are stored after the agent responds, so the first interaction has no prior context. Memories appear starting from the second interaction onward.
mem0ainot installed — If you seeImportError: mem0ai is required for Mem0Memory, runuv add mem0aiorpip install mem0aito add the dependency.- Invalid API key — A wrong or expired
MEM0_API_KEYwill log errors likeMem0 search failedorMem0 add failedbut won’t crash the agent. Check your key at app.mem0.ai. - Pipeline headers in memories — ChatDev automatically strips internal pipeline headers (e.g.,
=== INPUT FROM TASK (user) ===) before sending text to Mem0, so your memories stay clean. - Clearing test memories — To delete memories created during testing, use the Mem0 dashboard at app.mem0.ai or the Python SDK:
MemoryClient().delete_all(user_id="your-test-user").
Key Features
- Zero-Code Integration — Configure Mem0 entirely through YAML, no Python code required
- Cloud-Managed Storage — Mem0 handles embeddings, persistence, and search server-side
- Semantic Search — Retrieve contextually relevant memories, not just keyword matches
- Cross-Session Persistence — Memories survive across runs, sessions, and restarts
- Multi-Agent Memory Sharing — Multiple agents can share memories through common
user_idoragent_idscopes - Intelligent Input Processing — Only user input is stored; agent output is excluded to prevent noisy memories
Conclusion
By adding Mem0 as a memory store in ChatDev, your multi-agent workflows gain persistent, intelligent memory with zero code changes. Agents automatically remember past interactions and use that context to provide personalized, coherent responses across sessions.CrewAI Integration
Build multi-agent systems with CrewAI and Mem0
AutoGen Integration
Build conversational agents with AutoGen and Mem0