Skip to main content
Swap Agno’s in-memory database for a Synap-backed one. Agents that keep user memories (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
The Synap Agno integration ships two database classes that route user-memory operations through Synap. Pick by how your agent runs: Three more exports work on the agent rather than the database:
Use AsyncSynapDb with arun. Agno calls a sync database from inside the running event loop, so every Synap round trip blocks that loop, and in earlier releases several concurrent arun calls could crash it with IndexError: pop from an empty deque. SynapDb no longer crashes there, but it still blocks the loop for each call.

Setup

Install the package alongside Agno:
Installing the package also installs 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 ....
Configure your API key. Generate one from the Synap Dashboard.
Initialize the SDK once at application startup:
See SDK Initialization for the full lifecycle and configuration options.

Basic integration

The smallest useful integration constructs a SynapDb, 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:
For an async application, swap in AsyncSynapDb and await the run:
Notice that 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:
The overridden methods map to Synap as follows:

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 asks default_query (by default “What do you know about this user?”) and returns whatever is closest, a best-effort sample and not a full list. Set default_query on the database to the slice your agent should start with.
For this reason, Agno’s 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 passes user_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:
Each call hits Synap with its own 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.
The conversation Synap files the run under is Agno’s 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: one SynapDb and one Agent at module load, and a thin handler that supplies user_id per request:
Three things to notice in this pattern:
  1. One database, many users. The database is constructed once; user_id is the per-call scope, and session_id keeps each conversation’s turns apart.
  2. The customer_id is the tenant boundary. All users sharing a SynapDb instance are inside the same customer_id. For cross-tenant services, build a separate SynapDb per tenant.
  3. 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.
For services that serve many tenants, route requests to the matching 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_memories degrade gracefully: return empty results and log an error if Synap is unreachable.
  • upsert_user_memory surfaces failures: raises SynapIntegrationError so 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.
This is by design: read failures shouldn’t break a user-facing answer, but silent write failures would let memory drift away from reality.

Going further


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.