Skip to main content
Expose Synap memory to an AutoGen agent as two 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
The Synap AutoGen integration ships two drop-in tool classes, both implementing AutoGen’s 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 ....
Configure your API key. Generate one from the Synap Dashboard.
.env
Initialize the SDK once at application startup:
See SDK Initialization for the full lifecycle and configuration options.

Basic integration

The smallest useful integration registers both tools on an AssistantAgent and runs a task. The agent reads tool descriptions and decides whether to search or store:
The scoping triple (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.
Tool schema exposed to the model:
Returns a list of memory objects with 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.
Tool schema exposed to the model:
Returns {"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’s CancellationToken. 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:
This matters in long-running team conversations where one agent’s tool call should be cancellable by an orchestrator.

Complete example: assistant team with shared memory

The following team has two agents sharing the same Synap-backed memory: a Researcher that searches and stores, and a Planner that searches but never stores. Both run inside an AutoGen RoundRobinGroupChat:
Three things to notice in this pattern:
  1. Scope is per-tool, per-agent. Both agents see the same user’s memory, but only the Researcher can write. This is a common safety pattern: minimize the surface that can mutate memory.
  2. Memory is shared across agents. Anything Researcher stores during this run is immediately available to Planner on the next turn.
  3. CancellationToken flows 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.
For multi-tenant services, construct tools per request rather than caching them globally; each task should have its scope baked in.

Tuning retrieval mode

The model can pass mode: "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:
  • SynapSearchTool degrades gracefully: returns [] and logs an error
  • SynapStoreTool surfaces failures: raises SynapIntegrationError so the agent and caller know persistence failed
  • Cancellation is honored: both tools abort cleanly when CancellationToken.cancel() fires
This is by design: read failures shouldn’t break a team conversation, but silent write failures would corrupt the memory pool.

Going further


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.