Skip to main content
Make CrewAI’s built-in memory durable and queryable across crews. The integration plugs into CrewAI’s StorageBackend protocol, so existing crews keep working. They gain a long-term memory that survives restarts. A separate listener reports each run to Synap and, once Synap has compacted the conversation, sends the model Synap’s compaction in place of the history CrewAI built.
Requires Python 3.11+ and CrewAI 1.10 or later. The unified Memory class this integration plugs into does not exist in earlier CrewAI releases.

Overview

This guide shows how to add Synap to a CrewAI application to build crews that:
  • Persist Memory entries across executions and processes
  • Retrieve semantically-relevant context from prior crew runs
  • Scope memories per user or per organization
  • Report each run to Synap and use Synap’s compaction of the conversation
The Synap CrewAI integration ships these exports:
Use SynapMemory, not CrewAI’s plain Memory. CrewAI turns a recall question into an embedding and hands the storage backend only that embedding, never the question text. Synap embeds on the server and needs the text, so Memory(storage=SynapStorageBackend(...)) can save but can never recall. SynapMemory closes that gap.

Setup

Install the package alongside CrewAI:
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-crewai, but the import drops the maximem- prefix and uses underscores: from synap_crewai 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 gives SynapMemory a SynapStorageBackend. Every save inside the crew is routed to Synap, and recall returns ranked, semantically-matched results:
CrewAI’s memory machinery is now backed by Synap. Writes raise on failure so silent data loss is impossible. You can also call memory directly:
SynapMemory needs no embedding provider for storage: Synap embeds on the server, and CrewAI’s own duplicate checks use a small built-in local embedder. Pass embedder= (a callable) if you want CrewAI to use your own.

Core concepts

Lifecycle methods

SynapStorageBackend implements CrewAI’s StorageBackend protocol by mapping each method to the equivalent Synap operation:
CrewAI operations that have no direct Synap equivalent (notably delete) are no-ops with a warning logged. The memory pipeline keeps moving rather than blocking the crew.

Async support

SynapMemory works in both sync and async code. In an async application, await arecall:
When you call the backend directly, pass the question text yourself:
The synchronous search method wraps asearch via an event-loop bridge, so the same backend works in both sync and async crews. You don’t need separate configurations.

Report the run to Synap

SynapStorageBackend stores memories. It does not tell Synap what the crew is doing. SynapCrewAIListener does: build it before you kick off a crew and it reports the run from CrewAI’s event bus.
You do not call listen() yourself. The first event opens the gRPC stream, and the turns, tool calls, tool results and reasoning go on it. The stream gets up to 10 seconds to open. If it cannot open, the listener writes the user and assistant turns over REST instead, never both, and tries the stream once more a few seconds later, then no more than once a minute. Tool calls, tool results and reasoning exist only on the stream, so they are dropped while it is down. The REST write and the compaction lookup both need conversation_id to be a UUID. A stream you opened yourself is used as is. To keep the listener on REST, set SYNAP_AUTO_LISTEN=false. See gRPC vs REST. The listener never raises into CrewAI, and it does not slow the crew down: it hands each report to an event loop and returns. By default that is the loop running when you built the listener. Built from synchronous code, it uses a background loop of its own. If you opened a stream yourself on a loop the listener was not told about, it logs one warning and drops the reports. Build the listener from inside that loop, or pass loop=. Two options control what leaves your process:
  • report_tool_results=False stops 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.
  • report_kickoff_inputs=False stops the crew’s inputs from being reported as the user’s turn. CrewAI has no user message of its own: inputs are template variables, the closest thing to a request the framework has. When they are not what the user said, turn this off and write the real message before you kick off:

Synap’s compaction replaces CrewAI’s history

The listener also registers a before_llm_call hook. On the first model call of an executor, once Synap has compacted the conversation, every message CrewAI built before the current request (a history you passed to agent.kickoff(messages=...), for example) is replaced by Synap’s compaction, wrapped in <synap_conversation_history> tags, followed by the turns recorded after it. The current request is left as it is. Before the first compaction, or if Synap cannot answer, CrewAI’s messages are untouched. The hook is process-wide, as every CrewAI LLM hook is, so it applies to each crew that runs while the listener is live. CrewAI’s own context-window handling stays in place for the tool loop that follows the first call.

build_synap_st_backstory

build_synap_st_backstory fetches Synap’s short-term context for the conversation once and returns your backstory with it prepended, inside <synap_short_term_context> tags, for you to pass to Agent(backstory=...). It is a snapshot taken when you build the agent. Once the conversation has been compacted, a live listener removes that block on the first model call and sends Synap’s current history instead, so the two never both reach the model.
conversation_id is required. When Synap has no short-term context yet, or the call fails (the default on_error="fallback"), you get your base_backstory back unchanged. Pass on_error="raise" to get SynapIntegrationError instead.

Complete example: research crew with shared memory

The following crew chains a researcher and a writer. Both agents share the same Synap-backed memory, so the writer sees what the researcher learned, and the next crew kickoff has access to everything from earlier runs:
Three things to notice in this pattern:
  1. Memory survives the crew. Re-running kickoff with a new topic still benefits from the prior run’s findings.
  2. Scope is fixed at backend construction. All agents in this crew share the same user_id/customer_id. Build a separate crew per user if you need isolation.
  3. CrewAI’s built-in retrieval is unchanged. You don’t restructure tasks or prompts; the memory backend becomes Synap.

Advanced patterns

Multi-tenant scoping

SynapStorageBackend accepts the standard scoping triple: user_id (required), customer_id (B2B instances only), optional conversation_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 multi-tenant services, construct a backend per request; never share a backend whose scope doesn’t match the inbound user.

Sync and async in the same codebase

SynapStorageBackend supports both search (sync) and asearch (async). The sync method bridges to the async path via an event loop, so:
  • In a sync crew, call crew.kickoff() as usual; search works transparently.
  • In an async crew, prefer asearch for direct access; the framework will call it for you when you await crew tasks.

Failure semantics

The integration follows the Synap-wide contract:
  • search and asearch surface failures: when the Synap call fails they log an error and raise SynapIntegrationError. A search whose question text is unknown, which is CrewAI’s own duplicate check while saving, returns [] without calling Synap.
  • save surfaces failures: raises SynapIntegrationError so the crew (and caller) know if persistence failed.
  • Unsupported operations (e.g., delete) are no-ops with a warning rather than raising, so they don’t kill the crew.
  • SynapCrewAIListener and build_synap_st_backstory never break a run: a failed report is logged and dropped, and a failed history lookup leaves CrewAI’s messages as they were.
Writes and searches raise so that a failed save or an empty-looking recall is never silent.

Going further


Next steps

AutoGen

BaseTool implementations for AutoGen agents.

Pydantic AI

Deps and tools for Pydantic AI.

Memory Scopes

How user_id and customer_id interact across reads and writes.

Ingestion

Direct ingestion API for pipelines that need finer control than save.