ChatAgent persistent memory through Synap. CAMEL exposes a first-class pluggable memory interface (ChatAgent(memory=...) accepts any AgentMemory), and SynapAgentMemory plugs Synap in there, plus @tool functions and a short-term context helper. The memory also records each turn, tool call and tool result to Synap, and once Synap has compacted the conversation it sends the model Synap’s compaction in place of CAMEL’s earlier turns.
Requires Python 3.11+ and
camel-ai>=0.2.90.Overview
Three surfaces, mapped onto CAMEL’s own extension points. Adopt only the ones you need.
All three take an already-constructed
MaximemSynapSDK. Your app owns the SDK and its credentials.
Setup
maximem-synap (0.5.3 or later) and maximem-synap-integrations-common (0.2.3 or later). Set SYNAP_API_KEY in your environment; MaximemSynapSDK() reads it.
Basic integration
Register Synap as the agent’sAgentMemory; CAMEL then calls it for context on every turn.
Core concepts
SynapAgentMemory
Unlike a bolt-on store, CAMEL’sAgentMemory.get_context() is the sole source of the model’s input: it returns whatever the memory’s retrieve() yields. So Synap augments CAMEL’s history rather than replacing it: SynapAgentMemory subclasses ChatHistoryMemory (which keeps the live conversation) and adds two things.
- Recall.
retrieve()returns the real conversation (system + user + assistant) with Synap’s long-term memories prepended as a system context block, fetched viasdk.fetchusing the latest user turn as the query. A Synap blip degrades to the plain local history; recall never crashes the turn. - Recording. Each user and assistant turn is written to Synap as a conversation message under the memory’s
conversation_id. Synap compacts that conversation and turns it into long-term memory in the background, so future sessions remember it.
ChatAgent(memory=...)). Do not assign agent.memory = ... afterward; that path re-runs retrieve/clear/write and would amplify the injected context.
What gets recorded
You do not calllisten() yourself. The first write opens the gRPC stream, and the turn goes on it. The stream gets up to 10 seconds to open. If it cannot open, the turn is written over REST instead, never both, and the stream is tried once more a few seconds later, then no more than once a minute. A stream you opened yourself is used as is. To keep the memory on REST, set SYNAP_AUTO_LISTEN=false. See gRPC vs REST.
Tool calls, tool results and reasoning exist only on the stream, so they are dropped while it is down. A tool result is usually your own customer’s data. Synap uses it only as an anticipation hint and never stores it as a long-term memory, but it does leave your process.
CAMEL’s own summaries are never written back as turns. When CAMEL’s summarizer compacts the history, it adds an assistant
[CONTEXT_SUMMARY] message and rewrites the last user message; the real turns were already recorded, so those two are skipped, and so is Synap’s own history block.
Pass your own conversation_id
By default the conversation id is a UUID derived from the CAMEL agent’s id (0.1.4 or later), so the same agent keeps the same conversation across restarts. Passconversation_id= with your own UUID to continue one conversation across different agents or processes, and give the same one to synap_st_system_message if you use it.
What the model sees
ChatAgent builds its input from the memory’s retrieve(), so that is where Synap’s compaction goes. Once Synap has compacted the conversation, every record before the current turn is replaced by CAMEL’s system messages, Synap’s compaction block (in <synap_conversation_history> tags), and the turns recorded after it. The current turn is untouched. CAMEL’s own summarizer stays installed: on a history that short it does not fire, and when Synap has no compaction yet, or cannot answer, CAMEL’s records are left as they were.
create_synap_tools
For agents that want model-driven memory instead of, or alongside,SynapAgentMemory. Returns search_memory and store_memory as CAMEL FunctionTool objects.
synap_st_system_message
CAMEL’ssystem_message is a static string, so Synap’s compaction is folded into it once at construction, inside <synap_short_term_context> tags. Nothing is added until Synap has compacted the conversation. With SynapAgentMemory on the agent, the live compaction replaces this snapshot on every step, so you only need it for an agent that does not use the memory.
conversation_id is required. Empty context is a no-op; SDK failures are swallowed by default (on_error="fallback"), or set on_error="raise" for strict environments.
Complete example: multi-user support agent
Advanced patterns
Sync interface, async SDK
CAMEL’sAgentMemory methods are synchronous, so SynapAgentMemory bridges to the async Synap SDK internally (via the shared run_async helper). This works whether you drive the agent with agent.step(...) (sync) or agent.astep(...) (async), but construct the SDK, the memory, and run the agent on one asyncio event loop.
Error policy
- Reads (recall,
search_memory) degrade: a Synap failure returns no recall and the turn continues. A failed compaction lookup leaves CAMEL’s own history in place. - Turn writes run inside the agent loop, so they are best-effort by default (
on_error="fallback"): a transient outage never discards the model’s just-produced response. SetSynapAgentMemory(..., on_error="raise")to getSynapIntegrationErrorwhen a turn could not be written. - The explicit
store_memorytool raisesSynapIntegrationErroron failure.
Not a vector store
SynapAgentMemory deliberately does not reduce Synap to a VectorDBBlock behind CAMEL’s storage. It owns both the recall shape (Synap’s formatted context) and the write pipeline (server-side extraction), which a dumb vector backend would throw away.
Going further
- Scoping.
user_idandcustomer_idflow straight to Synap; per-user isolation and B2C/B2B scope are derived server-side from the ids you pass.
Next steps
SDK: Ingestion
How
memories.create extraction differs from conversation recording.Integrations overview
Every framework Synap plugs into.