BaseStore that any node can read and write, sends the model its own compaction of the conversation in place of the turns a graph has already sent, and records each run as it happens.
Requires Python 3.11+ and
langgraph 1.0 or later.Overview
This guide shows how to plug Synap into a LangGraph application to build graphs that:- Share long-term memory (user preferences, facts, episodes) across all threads belonging to the same user
- Send the model Synap’s compaction of the conversation instead of every earlier turn
- Report each run (turns, reasoning, tool calls and tool results) to Synap without changes to your nodes
How the integration connects
You do not open a connection yourself. The first turn the callback handler records opens Synap’s gRPC stream, and from then on turns, reasoning, tool calls and tool results go over it. Opening gets up to 10 seconds; if it fails, the handler tries once more a few seconds later, then no more than once a minute, and writes each turn over REST in the meantime, never both. It never raises inside your graph.- A stream your own code opened with
listen()is used as is. - To keep the integration on REST, set
SYNAP_AUTO_LISTEN=falsein the environment, or callset_auto_listen(sdk, False)fromsynap_integrations_common. - Tool calls, tool results and reasoning exist only on the stream. Without one they are not reported, and the turns still are.
- Initialize the SDK first (below). Until it is initialized the handler cannot open the stream.
Setup
Install the package alongside LangGraph. It installsmaximem-synap, maximem-synap-integrations-common and maximem-synap-langchain (0.3.3 or later) as dependencies.
The pip package is
maximem-synap-langgraph, but the import drops the maximem- prefix and uses underscores: from synap_langgraph import .....env
Basic integration
The smallest useful integration gives a prebuilt agent two things:synap_st_prompt as its prompt, so the model reads Synap’s compaction instead of its earlier turns, and the callback handler, so every turn is recorded:
synap_st_prompt asks Synap for the conversation’s compaction. What the model reads depends on the answer:
- Not compacted yet, or Synap cannot answer: your messages go through as they are, after your
systemprompt. A Synap outage is logged and never stops the run. - Compacted: Synap’s compaction goes above your
systemprompt, inside<synap_short_term_context>tags. Every turn before the current one is replaced by that compaction and the turns Synap holds after it. The current turn, including the tool calls and results of the run in progress, is left as it is.
create_react_agent is itself deprecated in favor of LangChain’s create_agent. If you use create_agent, add SynapHistoryMiddleware instead; see LangChain.
conversation_id is required and is never taken from the thread_id, because the two can differ. Build one prompt callable and one handler per conversation.
To share memory across threads, layer in SynapStore below.
Core concepts
Cross-thread memory
SynapStore implements BaseStore and gives every node in the graph access to long-term memory that spans all of the user’s threads:
store keyword argument that LangGraph injects:
asearch returns is the extracted text. The store puts that text under _raw unless it parses as a JSON object, so read m.value.get("_raw") as well as your own keys.
The scope comes from the store’s constructor, not from the namespace. SynapStore(sdk, user_id="alice", customer_id="acme") reads and writes user-scoped memory. SynapStore(sdk, customer_id="acme"), with no user_id, reads and writes the customer-wide pool that every user in the deployment sees. The namespace tuple is a label saved with each memory: asearch keeps the results whose label sits at or below the prefix you pass. See Memory Scopes for the full hierarchy.
Synap is search-based: agents ask it by search, and it has no exact key lookup or namespace listing. From maximem-synap-langgraph 0.6.0, aget, adelete and alist_namespaces (and their sync versions) raise SynapStoreUnsupportedError, a subclass of NotImplementedError, before anything is read or written. Read with asearch; each hit carries its Synap id in value["_synap"]["id"]. Delete with adelete_memory(namespace, memory_id) using that id, or aforget(namespace, "a description of it"). Before 0.6.0, aget returned None, adelete raised “no memory found” and alist_namespaces returned [].
SDK options on the store
The store exposes the Python SDK’s capabilities, so you rarely need to drop to the SDK. Standard LangGraph calls are unchanged; the additions are optional keyword arguments and extra methods, each with a sync twin. The user and customer always come from the namespace (or the constructor), never from an argument.aputtakesmemories.createoptions:document_type,document_id,document_created_at,mode,objective,metadata, andwait=Trueto wait for the ingestion.asearchtakesfetchoptions per call:mode,precision_level,types,query_date,max_results_per_query,conversation_id,scopes.- New methods:
acreate_memory,acreate_memory_from_file,aget_ingestion_status,await_ingestion,aget_memory,aupdate_memory,adelete_memory,aforget,adelete_data,arestore,adeletion_status,afetch_raw,aget_profile,aingest_transcript,aget_context_for_prompt,acompact,aget_compacted,aget_compaction_status,aget_scope_ladder.
asearch keeps mode="accurate" as its default, unlike sdk.fetch, which defaults to "fast". afetch_raw sends only what you pass, so it uses the SDK’s own defaults and returns the SDK’s UnifiedContextResponse.
memories.batch_create and conversation.record_messages_batch are not on the store: each item carries its own user ids, which would bypass the namespace. Call acreate_memory or arecord_message once per item, or use them on store.sdk. The full table is in the package README.
Short-term context in a custom graph
synap_st_prompt is an async callable that takes the graph state and returns the message list for the model. You can call it inside your own model node, which is the way to get the same compaction in a custom StateGraph:
create_synap_st_node(sdk, conversation_id) is a node that writes the compaction as a string into state["synap_st"] (change the key with state_key=). It adds the compaction only. It does not remove the turns the compaction covers from your messages, so a prompt assembled from that string and the full message list sends the covered turns twice. Use synap_st_prompt when you want them replaced.
create_synap_node(sdk, user_id="alice") is the long-term counterpart. It reads the latest user message from state, fetches matching memories and writes them into state["synap_context"].
Run reporting
SynapLangGraphCallbackHandler extends the LangChain handler for graphs. Pass it in the run config and it reports five things from inside a compiled graph: the user turn, the model’s reasoning, each tool call, each tool result and the assistant turn. A tool call and its result share an id, so Synap can pair them when several tools run at once.
It records one user turn and one assistant turn per run, not one per model call, so a tool loop does not repeat the question. Build a fresh handler per conversation rather than sharing one.
Tool results are usually your own customer’s data. They are anticipation hints and never become long-term memories, but they do leave your process.
Checkpoints
Synap does not store LangGraph checkpoints. Keep usingInMemorySaver in tests and SqliteSaver or PostgresSaver in production. They hold the graph’s own state; Synap holds the conversation’s memory and compaction.
Complete example: agent that remembers across threads
The following graph reads long-term memory from the store, sends the model Synap’s compaction in place of its earlier turns, and records every run. Each thread has its own state, and the assistant can recall facts from earlier conversations the same user had under a differentthread_id:
SynapStoreis read inrecall, so each thread draws on a user-level memory pool that the user’s earlier conversations filled.synap_st_promptdecides what history the model reads. Once Synap has compacted the conversation, that is the compaction and the turns after it.- The handler writes. It records the turns, so Synap extracts memories from them and the next thread can find them. You do not need a node that writes each exchange to the store.
Advanced patterns
Multi-tenant scoping
SynapStore takes user_id and customer_id (B2B instances only). The handler and the short-term helpers take a 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.
Streaming with reporting
The handler works withastream as it does with ainvoke:
Failure semantics
The Synap integration follows the Synap-wide contract:- Read failures degrade gracefully:
SynapStore.asearchreturns empty results and log an error.synap_st_promptlogs the failure and sends your messages and system prompt as they are, andcreate_synap_st_nodewrites an empty string. Passon_error="raise"to either to fail loudly. - Reporting never raises: the callback handler logs a failure and the graph keeps running.
- Write failures surface explicitly:
SynapStore.aputand the store’s SDK methods raiseSynapIntegrationErrorso callers know if persistence failed. - Unsupported methods raise:
aget,adeleteandalist_namespacesraiseSynapStoreUnsupportedError.
Going further
- Patterns overview: reusable memory patterns across frameworks.
- Cookbook overview: end-to-end worked examples.
Next steps
LangChain
Memory, retriever, and tools for LangChain chains and agents.
Memory Scopes
How
user_id, customer_id, and namespaces interact across stores.Context Fetch
The retrieval API that powers
SynapStore.asearch.Ingestion
Direct ingestion API for pipelines that need finer control than the store.