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.
Requires Python 3.11+.
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
BaseTool interface.
Setup
Install the package alongside AutoGen:The pip package is
maximem-synap-autogen, but the import drops the maximem- prefix and uses underscores: from synap_autogen import .....env
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, max_results, and mode, never the user identity. This prevents prompt-injection attempts from spoofing scope.
Core concepts
Search tool
SynapSearchTool is the read side. The model can override max_results and mode per call but cannot reach outside the scope bound at construction.
content, type, and confidence fields.
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 degrade gracefully: the tool returns [] and logs an error so the agent can continue.
Store tool
SynapStoreTool is the write side. The model supplies the content and an optional memory type; everything else is fixed at construction.
{"status": "stored", "id": "..."} 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:
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 accept the standard scoping triple:user_id (required), optional customer_id, optional conversation_id. customer_id is required on B2B Synap instances and ignored on single-tenant ones. See Memory Scopes.
Tuning retrieval mode
The model can passmode: "accurate" for higher-recall, slower lookups. For a global default, configure your system prompt to specify the mode the agent should prefer; the tool will respect whatever the model passes.
Failure semantics
The integration follows the Synap-wide contract:SynapSearchTooldegrades gracefully: returns[]and logs an errorSynapStoreToolsurfaces failures: raisesSynapIntegrationErrorso the agent and caller know persistence failed- Cancellation is honored: both tools abort cleanly when
CancellationToken.cancel()fires
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.