update_memory_on_run=True) keep working without code changes. They gain a persistent, semantically searchable memory store. Optional hooks also report each run to Synap and, once a conversation has been compacted, give the model Synap’s compaction in place of Agno’s earlier turns.
Requires Python 3.11+ and Agno 2.5 or later. The older
enable_user_memories option was removed in Agno 3.0 and now raises a TypeError; use update_memory_on_run=True.Overview
This guide shows how to add Synap to an Agno application to build agents that:- Persist user memories across processes and deployments
- Retrieve memories semantically rather than by raw key lookup
- Serve many users from a single database instance, scoped per-call by
user_id - Report each run to Synap and use Synap’s compaction of the conversation
Three more exports work on the agent rather than the database:
Setup
Install the package alongside Agno:maximem-synap (0.5.3 or later) and maximem-synap-integrations-common (0.2.3 or later).
The pip package is
maximem-synap-agno, but the import drops the maximem- prefix and uses underscores: from synap_agno import ....Basic integration
The smallest useful integration constructs aSynapDb, hands it to an Agent, and turns on update_memory_on_run. Each agent.run(..., user_id=...) call now reads and writes against Synap rather than a process-local dict:
AsyncSynapDb and await the run:
user_id is supplied per call. SynapDb is constructed once and serves all users in the process. The customer_id (organization scope) is fixed at construction. Memory reads degrade gracefully on Synap outages; writes raise so silent data loss is impossible.
Core concepts
SynapDb
SynapDb extends Agno’s InMemoryDb and overrides the user-memory methods. Everything else (session state, non-memory storage) is inherited unchanged, so existing Agno code continues to work. AsyncSynapDb does the same for Agno’s async interface:
How reading works
Synap retrieval answers a question; it does not list everything stored for a user. A fetch with no question returns nothing, and a very generic question can return nothing when only a few memories exist. So:get_user_memories(user_id=..., search_content="seating preferences")returns what matches that topic. This is the reliable way to read.get_user_memories(user_id=...)with no search term asksdefault_query(by default “What do you know about this user?”) and returns whatever is closest, a best-effort sample and not a full list. Setdefault_queryon the database to the slice your agent should start with.
add_memories_to_context, which loads a user’s memories without a question, only injects what the default question happens to match. For deliberate lookups, give the agent a search tool.
Per-call user scoping
Agno passesuser_id as a runtime argument to every memory call rather than baking it into the database. That means one SynapDb instance can serve any number of users:
user_id scope, so memories never leak between users, even though the database object is shared.
Report the run to Synap
The database stores user memories. It does not tell Synap what the agent is doing.create_synap_hooks does: it returns the pre_hooks and post_hooks an Agent takes, so you splat it into the constructor.
session_id. Pass conversation_id= to create_synap_hooks to key it your own way. The user comes from the user_id you pass to run, so one agent can serve many users.
You do not call
listen() yourself. The first run 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. Reasoning, tool calls and tool results exist only on the stream, so they are dropped while it is down. The REST write and the compaction lookup both need the session id to be a UUID, which the ids Agno generates are. A stream you opened yourself is used as is. To keep the hooks on REST, set SYNAP_AUTO_LISTEN=false. See gRPC vs REST.
The tool and reasoning events arrive after the run, not during it. Agno’s tool hooks carry no call id, so the integration reads the finished run instead, where each call and result share one. The batch lands just before the assistant turn.
Pass report_tool_results=False to stop 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.
Sync and async runs
Agno’s sync path (agent.run) skips coroutine hooks with a warning. create_synap_hooks therefore returns plain functions, which work on both run and arun. On arun they reach the async SDK through a loop patch that does not work on every event loop (uvloop, for one). If you only ever call arun, use create_synap_async_hooks instead, which takes the same arguments and returns coroutine hooks:
Synap’s compaction replaces Agno’s history
The same pre-hook asks Synap for the conversation before Agno builds the run’s messages. Once Synap has compacted it, the history Agno reads for this run is Synap’s: the compaction block, wrapped in<synap_conversation_history> tags and sent as a user message, then the turns recorded after it. Earlier turns are not sent. The current message is untouched, and the runs Agno has stored are never edited. The post-hook removes the swap when the run ends.
When Synap has no compaction yet, or cannot answer, Agno’s history is left alone, and so is Agno’s own compaction if you configured one.
synap_st_instructions
synap_st_instructions returns an async callable for Agent(instructions=...). It adds Synap’s compaction block, inside <synap_short_term_context> tags, above your own instructions. Use it when you want the compaction without the hooks. With the hooks on the agent it adds nothing, because the history already carries the block. Because the callable is async, run the agent with arun.
conversation_id is required. If Synap has no compaction yet, or fails (the default on_error="fallback"), only your own instructions are used. Pass on_error="raise" to get SynapIntegrationError instead.
Complete example: long-lived agent serving many users
The pattern below is what most production Agno deployments end up with: oneSynapDb and one Agent at module load, and a thin handler that supplies user_id per request:
- One database, many users. The database is constructed once;
user_idis the per-call scope, andsession_idkeeps each conversation’s turns apart. - The
customer_idis the tenant boundary. All users sharing aSynapDbinstance are inside the samecustomer_id. For cross-tenant services, build a separateSynapDbper tenant. - Agno’s behavior is unchanged.
update_memory_on_run,description, and run signatures all work exactly as in vanilla Agno; you’ve only swapped the storage layer.
Advanced patterns
Multi-tenant scoping
SynapDb takes the customer-tenant scope at construction (customer_id) and the user scope per call (user_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.
SynapDb rather than mixing tenants on one instance.
Memory topic discovery
get_all_memory_topics is implemented as a broad Synap search and returns unique topics across the user’s memory pool. Useful for building UIs that let a user browse what’s been remembered about them, or for prompt enrichment (“Here are the topics we’ve discussed: …”).
Failure semantics
The integration follows the Synap-wide contract:get_user_memory/get_user_memoriesdegrade gracefully: return empty results and log an error if Synap is unreachable.upsert_user_memorysurfaces failures: raisesSynapIntegrationErrorso the agent and caller know persistence failed.- The hooks never break a run: a failed report or history lookup is logged and dropped, and Agno carries on with its own history.
Going further
- Patterns overview: reusable memory patterns across frameworks.
- Cookbook overview: end-to-end worked examples.
Next steps
Google ADK
FunctionTool factory for Google ADK agents.OpenAI Agents
Function tools for the OpenAI Agents SDK.
Memory Scopes
How
user_id and customer_id interact across reads and writes.Ingestion
Direct ingestion API for pipelines that need finer control than
upsert_user_memory.