CAMEL-AI Memory
Give CAMEL’s ChatAgent persistent memory with one constructor argument. MemorySyncMemory keeps verbatim history locally and losslessly, sends each user turn to MemorySync, where only the durable facts in it are stored, injects scored semantic recall right after the system prompt under a hard budget, and needs zero client-side embeddings.
How it works
- Install
camel-memorysyncfrom PyPI. - Pass
memory=MemorySyncMemory(...)to yourChatAgent. - Every user turn is sent to MemorySync, which extracts the durable facts in it and stores only those; assistant replies are not sent, and your verbatim history stays local.
- On each step, the user’s relevant memories are recalled and injected after the system prompt — days later, in new sessions, in other frameworks.
Before you start
- A MemorySync API key. Create one in the dashboard under Settings → API Keys, inside a project.
- Python 3.10+ with
camel-ai0.2.60 or newer.
Install
One package:
pip install camel-memorysync
Quickstart
Step 1 — hand the agent its memory
from camel.agents import ChatAgentfrom camel_memorysync import MemorySyncMemorymemory = MemorySyncMemory(user_id="customer-42", # required — who these memories belong tosession_id="support", # session scope — tags this conversation's facts)agent = ChatAgent(system_message="You are a helpful travel assistant.",memory=memory,)
Step 2 — teach it, then ask later
agent.step("I always prefer window seats on long flights")# a new session, days later:agent.step("which seat should I book for the Oslo flight?") # remembers
How recall enters the context
CAMEL’s ScoreBasedContextCreator sorts records by timestamp. The recall block is ONE SYSTEM-role record with timestamp=0.0, so it lands right after the system prompt — your history is never reordered, rewritten, or role-swapped. An anti-echo filter drops any match already present verbatim in the live context, so the question the user just asked can never come back as a “memory”.
[system] You are a helpful travel assistant.[system] Relevant long-term memories about this user:- Prefers window seats on long flights[user] which seat should I book for the Oslo flight?
Advanced: the storage seam
If you compose CAMEL memories yourself, MemorySyncStorage slots into CAMEL’s own ChatHistoryMemory as a BaseKeyValueStorage. save() keeps verbatim records locally (exact round-trip) and sends each user turn to MemorySync, which extracts the durable facts in it and stores only those; assistant replies are not sent, and system prompts and tool chatter never leave the process. A retried save is recognised server-side, so each turn is extracted once:
from camel.memories import ChatHistoryMemory, ScoreBasedContextCreatorfrom camel.types import ModelTypefrom camel.utils import OpenAITokenCounterfrom camel_memorysync import MemorySyncStoragememory = ChatHistoryMemory(context_creator=ScoreBasedContextCreator(OpenAITokenCounter(ModelType.GPT_4O_MINI), 2048),storage=MemorySyncStorage(user_id="customer-42", session_id="support"),)
Deletion — designed against data loss
| Call | What happens |
|---|---|
clear() | Resets the LOCAL conversation window only — remote memories survive |
forget_session() | Deletes the facts extracted from THIS session’s turns and returns the number deleted (loud — failures raise) |
forget_user() | Deletes the facts extracted from all of this user’s CAMEL turns (every camel-surface memory) and returns the number deleted; other surfaces’ memories survive |
Configuration
| Parameter | Default | Meaning |
|---|---|---|
user_id | — (required) | End user the memories belong to |
session_id | default | Session scope camel::<session> — tags this conversation’s facts; bounds forget_session() |
top_k | 5 | Memories per recall |
recall_timeout | 1.2 | Hard recall budget in seconds |
min_query_chars | 8 | Skip recall for trivial topics |
extraction | True | Send the user’s turns to MemorySync for fact extraction |
context_creator | ScoreBased / 2048 tokens | Any BaseContextCreator |
Quotas and plan limits
Hitting a monthly plan limit never breaks a conversation. Over-limit writes are accepted without storing and recalls return empty — the agent keeps answering from live history. Evaluation keys instead surface a truthful 429, so limits show up in testing, not production.
Troubleshooting
- Import crash mentioning `FastMCP` — the installed
mcprelease is newer than camel-ai supports. Reinstallcamel-memorysyncto restore a compatible version. - A recall was skipped — the 1.2s budget fails open to history-only, and topics under
min_query_charsskip recall by design. - A “memory” repeats the question just asked — cannot happen: the anti-echo filter drops matches already present in the live context. If you see it, the text differed — check the stored fact.
- `clear()` didn’t delete remote memories — by design. Use
forget_session()orforget_user()for explicit, scoped remote deletes.
Supported versions
| Surface | Requires | Verified on |
|---|---|---|
camel-memorysync 1.1.0 | camel-ai 0.2.60+ (Python 3.10+) | 33 CI checks against the latest camel-ai: REAL ChatAgent turns via CAMEL’s own StubModel — the byte-exact local round-trip including a PIL image, role preservation in local history, only user turns sent to MemorySync, local-only clear with explicit scoped forgets, the anti-echo filter, timestamp-0 placement through the real ScoreBasedContextCreator, the 1.2s budget, seed idempotency, and both monthly-quota server modes |
How it compares
CAMEL ships a Mem0 storage inside its own repo — the only other memory SaaS in the ecosystem. Verified against its source:
| Mem0 (`Mem0Storage`, in-repo) | Zep | Supermemory | MemorySync | |
|---|---|---|---|---|
| History round-trip | ✗ broken — load() returns extracted facts, not your messages | — nothing at all | — nothing at all | ✓ byte-exact: from_dict reconstructs every record |
| Message roles | ✗ every record hardcoded `role=USER` — OpenAI alternation breaks | — | — | ✓ preserved exactly |
clear() blast radius | ✗ calls `client.delete_users()` — the entire user entity | — | — | ✓ local window only; remote wipes are explicit and scoped |
agent_id filter | ✗ silently overwritten by the user_id filter | — | — | ✓ both preserved per record |
| Failures | ✗ every exception swallowed — callers never know | — | — | ✓ conversation always works, failures logged loudly; explicit deletes raise |
| Multimodal | ✗ image_list/video_bytes silently discarded | — | — | ✓ full media round-trip (base64) |
| Recall latency guard | ✗ none | — | — | ✓ 1.2s hard budget, fails open to history-only |
| Client-side embeddings | n/a | — | — | ✓ none needed (CAMEL’s own VectorDBMemory defaults to OpenAIEmbedding() + a vector DB you operate) |