BaseTool implementations. The agent decides when to call each, and both tools cooperate with AutoGen’s CancellationToken so a long search can be aborted mid-flight. A model context reports the conversation to Synap and, once Synap has compacted it, gives the model Synap’s compaction in place of AutoGen’s earlier turns.
Requires Python 3.11+ and
maximem-synap 0.5.18 or later. autogen-core pins protobuf 5.29, and earlier SDK versions need a newer protobuf, so their gRPC stream cannot open and every turn goes over REST. If you installed before, run pip install -U maximem-synap.Overview
This guide shows how to add Synap to an AutoGen application to build agents that:- Recall user-specific facts, preferences, and past conversations
- Persist new information surfaced during a conversation
- Respect AutoGen’s cooperative cancellation model so memory calls don’t leak past a cancelled task
- Report each run to Synap and use Synap’s compaction of the conversation
BaseTool interface, and two model contexts.
Setup
Install the package alongside AutoGen:maximem-synap, maximem-synap-integrations-common and autogen-core (0.4 or later). Make sure maximem-synap resolves to 0.5.18 or later, as noted above.
The pip package is
maximem-synap-autogen, but the import drops the maximem- prefix and uses underscores: from synap_autogen import ....Basic integration
The smallest useful integration registers both tools on anAssistantAgent and runs a task. The agent reads tool descriptions and decides whether to search or store:
user_id, optional customer_id) is bound at construction. The model only ever sees query and content, never the user identity. This prevents prompt-injection attempts from spoofing scope.
Core concepts
Search tool
SynapSearchTool is the read side. The model supplies only the question and cannot reach outside the scope bound at construction.
SearchMemoryResult with one context field: the formatted memory context as a string, or "No relevant memories found." when nothing matches.
The mode you pass at construction sets how the tool searches. The two retrieval modes trade latency against comprehensiveness:
fast is lower-latency and suited to the hot path; accurate adds LLM-driven query decomposition and reranking for relationship-aware queries at a higher latency cost.
Search failures surface: an SDK error is logged and raised as SynapIntegrationError, so a failed search is never mistaken for an empty memory.
Store tool
SynapStoreTool is the write side. The model supplies the content; everything else is fixed at construction.
StoreMemoryResult with ingestion_id and a confirmation message on success. Store failures surface explicitly: the tool raises SynapIntegrationError so the agent (and you) know if persistence failed.
Cooperative cancellation
Both tools propagate AutoGen’sCancellationToken. When the token is cancelled, the in-flight Synap call is aborted and the tool returns control to the agent rather than continuing to completion:
Report the run to Synap
The tools let the model search and store. They do not tell Synap what the conversation is.SynapStreamingChatContext does: it wraps the agent’s model_context, which every message an AssistantAgent produces passes through, and reports each one.
You do not call
listen() yourself. The first message opens the gRPC stream, and everything above goes on it. The stream gets up to 10 seconds to open. If it cannot open, the user and assistant turns are written over REST instead, never both, and the stream is tried once more a few seconds later, then no more than once a minute. Tool calls, tool results and thoughts exist only on the stream, so they are dropped while it is down. The REST write and the compaction lookup both need conversation_id to be a UUID. A stream you opened yourself is used as is. To keep the context on REST, set SYNAP_AUTO_LISTEN=false. See gRPC vs REST. The context never raises into the agent’s loop.
Two options control what leaves your process:
report_tool_results=Falsestops tool results from being reported. 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.report_thoughts=FalsestopsAssistantMessage.thoughtfrom being reported. Most providers return nothing there.
inner= to wrap a context you already use, such as BufferedChatCompletionContext. It stays installed and is what the agent sees until Synap has compacted the conversation.
Call report_reply after each run
By default (reflect_on_tool_use is False unless you set output_content_type), a turn that ends in a tool call is answered with a ToolCallSummaryMessage, and AutoGen never adds that message to the model context. The context cannot see the reply. It reports the turn the only way it can: it keeps the tool results and, when the next user message arrives, writes them as the assistant turn in AutoGen’s default summary format. That is not the text your tool_call_summary_format produced. report_reply(result) sends the exact reply as soon as the run returns and cancels the stand-in. It does nothing when the reply was already reported, so calling it after every run is safe. It returns True when it wrote the reply.
Teams
In a team, every agent receives the task and every other agent’s reply as aUserMessage. Contexts in one process that share a conversation_id write each of those once: an agent’s own reply is written as an assistant turn by its context, and the others skip it. Contexts in different processes cannot see each other, so give the context to one agent only.
Synap’s compaction replaces AutoGen’s earlier turns
AnAssistantAgent builds every model call from model_context.get_messages(), so that is where Synap’s compaction goes. Once Synap has compacted the conversation, SynapStreamingChatContext.get_messages() returns your system messages, one system message with Synap’s compaction (in <synap_conversation_history> tags), the turns recorded after it, and the current turn. Earlier turns, and the tool calls and results that belonged to them, are not sent. The current turn, from the last user message on, is untouched.
When Synap has no compaction yet, or cannot answer, the wrapped context’s messages are returned as they were. A BufferedChatCompletionContext you pass as inner stays in place as that fallback.
SynapShortTermChatContext
SynapShortTermChatContext does the same replacement without reporting anything. Use it when your own code already records the conversation, or when you only want the compaction.
conversation_id is required. Pass inner= to wrap another context. With the default on_error="fallback", a failed lookup returns the wrapped context’s messages unchanged; on_error="raise" raises SynapIntegrationError instead. You can wrap a SynapShortTermChatContext as the inner of SynapStreamingChatContext; the compaction is applied once.
Complete example: assistant team with shared memory
The following team has two agents sharing the same Synap-backed memory: aResearcher that searches and stores, and a Planner that searches but never stores. Both run inside an AutoGen RoundRobinGroupChat:
- Scope is per-tool, per-agent. Both agents see the same user’s memory, but only the
Researchercan write. This is a common safety pattern: minimize the surface that can mutate memory. - Memory is shared across agents. Anything
Researcherstores during this run is immediately available toPlanneron the next turn. CancellationTokenflows automatically through AutoGen’s task group, so cancelling the team also cancels any in-flight Synap calls.
Advanced patterns
Multi-tenant scoping
Both tools takeuser_id (required) and customer_id (B2B instances only). SynapSearchTool also takes an optional conversation_id. customer_id is required on B2B Synap instances and not accepted on B2C (single-tenant) ones, where a call carrying it is rejected with HTTP 400. See Memory Scopes.
Tuning retrieval mode
The model cannot choose the mode: you fix it when you construct the tool. Usemode="fast" for latency-sensitive chat, or leave the default "accurate" for multi-entity questions.
Failure semantics
The integration follows the Synap-wide contract:SynapSearchToolsurfaces failures: logs an error and raisesSynapIntegrationError, so the agent never reads a failed search as “nothing remembered”SynapStoreToolsurfaces failures: raisesSynapIntegrationErrorso the agent and caller know persistence failed- Cancellation is honored: both tools abort cleanly when
CancellationToken.cancel()fires - The model contexts never break a run: a failed report or history lookup is logged and dropped, and the agent carries on with AutoGen’s own messages
Going further
- Patterns overview: reusable memory patterns across frameworks.
- Cookbook overview: end-to-end worked examples.
Next steps
OpenAI Agents
Function tools for the OpenAI Agents SDK.
CrewAI
Storage backend for CrewAI crews.
Context Fetch
The retrieval API behind
SynapSearchTool: modes, scopes, and response shapes.Memory Scopes
How
user_id and customer_id interact across reads and writes.