Skip to main content
Give a Strands Agents agent persistent memory through Synap. Unlike bolt-on integrations, Synap plugs into Strands’ own extension points: a native MemoryStore for long-term memory, hooks for compacted history and real-time reporting, and @tool functions for explicit control.
Requires Python 3.11+ and strands-agents>=1.48.

Overview

Four surfaces, each mapped onto a native Strands extension point. Adopt only the ones you need. All four take an already-constructed MaximemSynapSDK. Your app owns the SDK and its credentials. The hook opens the real-time stream itself on the first turn.

Setup

Installing the package also installs maximem-synap (0.5.3 or later) and maximem-synap-integrations-common (0.2.3 or later).

Basic integration

Register Synap as a Strands MemoryStore; MemoryManager then handles recall, automatic prompt injection, and extraction.

Core concepts

SynapMemoryStore

A structural implementation of Strands’ MemoryStore protocol.
  • search reads Synap’s long-term layer via sdk.fetch and returns structured MemoryEntry objects (facts, preferences, episodes, emotions, temporal events). Reads degrade gracefully: a Synap blip returns [] rather than crashing recall.
  • add_messages is the primary write sink. MemoryManager hands it conversation batches, and it records each user and assistant message as a conversation turn: on the real-time stream, opened on first use, or over REST when the stream cannot carry it, never both. Synap extracts long-term memory from the conversation it keeps. A turn that SynapStreamHook already wrote is skipped, so the store and the hook compose without extracting a turn twice. If a turn cannot be recorded, add_messages raises SynapIntegrationError, and MemoryManager retries the batch.
  • add ingests a single fact via sdk.memories.create.
Pass conversation_id to the store so its turns land in the same conversation as the hook’s. Left unset, the store records under a fresh id of its own.

SynapShortTermHook

Strands keeps the conversation in agent.messages and sends all of it, so the hook replaces earlier turns instead of adding a second copy. On the first turn it installs model-call middleware on the agent. Once Synap has compacted the conversation, every call to the model is sent Synap’s compaction block (in <synap_conversation_history> tags) and the turns after it, in place of every turn before the current one. The current turn, including a tool call and its result, is untouched. agent.messages is not rewritten, so Strands’ own conversation manager keeps working on it and is what the model is sent whenever Synap has no compaction or cannot answer.
SynapStreamHook installs the same middleware on its first turn, so either hook gives you the replacement. conversation_id is required, explicit and must be a UUID. SDK failures are swallowed by default (on_error="fallback"), or set on_error="raise" for strict environments. The hook has one more job. When an agent starts with an empty agent.messages (after a restart, say) and Synap has no compaction yet, it folds Synap’s short-term context into the first user message, so the model still knows what came before. With a non-empty history, or once a compaction exists, nothing is folded.
The middleware needs a version of strands-agents with model-call middleware (strands.middleware, or strands._middleware on earlier versions). On one with neither, the hook logs a warning once and leaves the messages alone.
Strands exposes no ephemeral per-call injection hook to user code, so the context the hook folds into the first user message stays in the conversation the agent persists. The hook guards against folding it twice, and the stream hook does not record it as something the user said.

create_synap_tools

For agents that want explicit control instead of MemoryManager. Returns search_memory and store_memory as Strands @tool functions.

SynapStreamHook

Reports the agent’s turns, tool calls and tool results to Synap on the real-time stream, which it opens on the first turn. See Advanced patterns.

Complete example: multi-user support agent

Advanced patterns

Real-time reporting and anticipation

SynapStreamHook writes the agent’s user and assistant turns, and reports each tool call and its result with the same call id, so Synap’s anticipation agent can pre-fetch context before the agent asks. A tool that raised is reported too, as an error result. You do not call listen(): the first turn opens the stream. See Real-time anticipation for the model, and Real-time anticipation in a server for running it in a multi-tenant process.
  • Opening the stream. The open gets up to ten seconds. After a failure the hook tries once more a few seconds later, then no more than once a minute, and in the meantime each turn is written over REST. It never raises into the agent.
  • If the stream cannot carry a turn, the turn goes over REST, never both. Tool calls and results exist only on the stream, so they are dropped in that case, without an error.
  • Stay on REST. Set SYNAP_AUTO_LISTEN=false, or call set_auto_listen(sdk, False) from synap_integrations_common, and the hook never opens a stream. A stream your own code opened with await sdk.instance.listen() is used as is.
  • Event loops. The stream belongs to the event loop that opened it, and a write from another loop is not sent over it. Run the agent with invoke_async on one loop so the stream stays open between turns. If the loop closes, the next turn replaces the stream, and after a few of those the integration stays on REST.
Use a real UUID for conversation_id. The stream accepts any string, so a free-form id like "conv_abc" appears to work there, but every call that reads the conversation back (fetch, record_message, compaction) rejects it with InvalidConversationIdError, leaving you with a conversation you cannot read back or compact.
The turns the hook writes are persisted server-side and are promoted into long-term memory when the conversation compacts. SynapMemoryStore.add_messages skips the turns the hook already wrote, so pairing them does not extract a turn twice. See What the stream does to memory.

Not SessionManager

This integration does not implement Strands’ SessionManager / snapshot storage. That persists opaque conversation snapshots for replay, a different concern from Synap’s semantic memory. Use FileSessionManager / S3SessionManager for durable sessions and a SynapMemoryStore for memory; they compose.

Going further

  • Error policy. SynapMemoryStore.search degrades and returns []. The writes (add, add_messages) and both tools (search_memory, store_memory) raise SynapIntegrationError. The hooks log and never raise; with no compaction, or on an error, the model is sent Strands’ own messages.
  • Scoping. user_id and customer_id flow straight to Synap; per-user isolation and B2C/B2B scope are derived server-side from the ids you pass.

Next steps

SDK: Ingestion

How memories.create extraction and conversation recording differ.

Integrations overview

Every framework Synap plugs into.