Skip to main content
Give LangGraph graphs and agents long-term memory and a short-term history that does not grow without bound. Synap exposes a cross-thread 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
The Synap LangGraph integration ships five components. Each one uses a native LangGraph or LangChain interface, so you do not have to wrap or re-implement anything.
SynapCheckpointSaver is deprecated, and constructing it raises a FutureWarning. Synap extracts facts from what it is given and returns those, not the checkpoint, so a thread resumed through it starts from scratch. Use SqliteSaver or PostgresSaver for checkpoints and SynapStore for long-term memory.

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=false in the environment, or call set_auto_listen(sdk, False) from synap_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.
See gRPC vs REST for what the stream carries.

Setup

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

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:
On every model call, 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 system prompt. A Synap outage is logged and never stops the run.
  • Compacted: Synap’s compaction goes above your system prompt, 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.
The graph’s own state is never changed: the prompt decides only what the model sees. LangGraph’s 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:
Inside a graph node, access the store through the store keyword argument that LangGraph injects:
A write is an ingestion, not a key-value put. Synap extracts memories from what you write, so what 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.
  • aput takes memories.create options: document_type, document_id, document_created_at, mode, objective, metadata, and wait=True to wait for the ingestion.
  • asearch takes fetch options 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.
Calls that take an id (aget_memory, aupdate_memory, adelete_memory, aget_ingestion_status, await_ingestion, arestore, adeletion_status, and the methods that take a conversation_id) do not check the id against the namespace. The server does not verify who owns an id, so any caller holding one can read, change or delete what it points to. Do not pass ids from untrusted input, such as a model’s tool call, without your own check.
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:
If you build the prompt yourself, 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 using InMemorySaver 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 different thread_id:
Three things to notice in this pattern:
  1. SynapStore is read in recall, so each thread draws on a user-level memory pool that the user’s earlier conversations filled.
  2. synap_st_prompt decides what history the model reads. Once Synap has compacted the conversation, that is the compaction and the turns after it.
  3. 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 with astream as it does with ainvoke:

Failure semantics

The Synap integration follows the Synap-wide contract:
  • Read failures degrade gracefully: SynapStore.asearch returns empty results and log an error. synap_st_prompt logs the failure and sends your messages and system prompt as they are, and create_synap_st_node writes an empty string. Pass on_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.aput and the store’s SDK methods raise SynapIntegrationError so callers know if persistence failed.
  • Unsupported methods raise: aget, adelete and alist_namespaces raise SynapStoreUnsupportedError.
This is by design: a transient outage should never break a user-facing turn, but a silent write loss would go unnoticed.

Going further


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.