Update, 28 October 2026: Synap is now #1 on LongMemEval at 95.6% on all 500 questions. Read the results.
LangChain Long-Term Memory: Remembering Users Across Sessions
Maximem Team
May 20, 2026
LangChain remembers a user across sessions through a LangGraph store, and remembers one conversation through a checkpointer. A checkpointer saves messages under one thread_id, so a returning user in a new thread starts empty. A store keeps JSON documents under a namespace and key you design, readable from any thread, but your code decides what to write, how a changed fact replaces an old one, and how users stay separate. Maximem Synap, through the maximem-synap-langchain package, records each turn through a callback handler and returns memories scoped by user_id through a standard LangChain retriever. For thread memory and the step-by-step setup, read How to Add Conversational Memory to a LangChain App.
Where LangChain Excels
LangChain covers the building blocks of an agent well. Composable chains and tool routing, prompt templating and output parsing, vector store integrations and output guardrails are all first-class, and since 1.0 the recommended entry point is create_agent, which runs on LangGraph and inherits its persistence. If your agent needs to call APIs or reason across multiple steps, LangChain handles the logic and orchestration well.
The open question is the user who comes back tomorrow in a new thread.
How LangChain Memory Works Today
LangChain 1.x splits memory into two mechanisms, and both persist when you back them with a database.
Short-term memory is a checkpointer passed to create_agent. InMemorySaver keeps a thread's messages for the life of the process, and the docs tell you to use a database-backed checkpointer such as PostgresSaver in production, which keeps every thread across restarts and instances. The scope is the thread: a new thread_id is a new, empty conversation, by design.
Long threads are handled by middleware. SummarizationMiddleware replaces older messages with a summary once a token threshold is crossed. Summaries are lossy, and repeated rewriting compounds the loss: in the ACE paper from Stanford, SambaNova and UC Berkeley, an agent's context collapsed in a single rewrite on the AppWorld benchmark from 18,282 tokens at 66.7% accuracy to 122 tokens at 57.1%, below the 63.7% it scored with no adapted context at all.
Long-term memory is a store passed to the same create_agent call. It saves JSON documents under a namespace (similar to a folder) and a key (like a file name), namespaces often carry a user or organization ID, and tools read and write it through runtime.store with the user's ID taken from the runtime context. InMemoryStore is for development; the docs say to use a database-backed store such as PostgresStore in production.
The classic classes (ConversationBufferMemory, ConversationBufferWindowMemory, ConversationSummaryMemory and VectorStoreRetrieverMemory) now live in the langchain-classic package and carry deprecation warnings that point to create_agent with checkpointing or the store.
So LangChain gives you a durable place to keep what you know about a user. It does not decide what is worth keeping. Choosing which sentence of a forty-turn conversation becomes a memory, noticing that "I moved to Berlin" replaces "I live in Lisbon", and keeping one tenant's users away from another's is the part your code owns.
What Synap Adds
Synap is agentic context management: a hosted memory engine with open-source client packages. It does not replace your checkpointer, which should keep doing thread state. It takes over the cross-session job, so extraction and updates run on Synap's side instead of in your tools.
The maximem-synap-langchain package plugs into LangChain's own interfaces. Four pieces matter for remembering a user:
SynapCallbackHandler is an AsyncCallbackHandler. Pass it in the run config and it records the user message when the chat model starts and the assistant message when it finishes. No change to your chain logic is needed, and a recording failure is logged at ERROR and never raised into the chain.
SynapRetriever implements BaseRetriever. It fetches memories for one user_id and returns them as standard LangChain Document objects, typed in metadata as fact, preference, episode, emotion or temporal event. Two modes: fast, built for a live conversation, and accurate, which breaks a compound question into parts and follows relationships between entities at a higher latency. Accurate is the default, so set mode="fast" for a retrieval that runs before every reply.
SynapSearchTool and SynapStoreTool are BaseTool classes, exposed to the model as search_memory and store_memory, for agents that should decide for themselves when to look something up or write it down.
SynapChatMessageHistory implements BaseChatMessageHistory, which LangChain deprecated in langchain-core 1.6.4, so treat it as a bridge for existing RunnableWithMessageHistory code.
We built this because agents kept stalling in production. Not from bad chain logic. From missing context that lived in a different session last Tuesday. On our open eval harness, Synap scores 92% 95.6% on LongMemEval (500 questions, Gemini 3.8 Flash as answer model and gpt-4o as judge) and 93.2% on LoCoMo (1,540 questions, gpt-5-mini as both answer model and judge); in-conversation reads come from a cache Synap pre-fetches into your own process at an asserted P75 under 15ms, and a cold retrieval targets P95 450ms.
For why context management is infrastructure and not a feature, read What Is Agentic Context Management? For build-versus-buy numbers, see The Real Cost of DIY Agent Memory.
What Synap Adds to LangChain
PERSISTENCE
LangChain 1.x: A database-backed checkpointer keeps each thread across restarts, and a database-backed store keeps cross-thread documents. You run both.
With Synap: Per-user memory is hosted and survives across sessions and restarts.
ENTITY RESOLUTION
LangChain 1.x: Not a store feature. Documents hold the identifiers your code wrote.
With Synap: "My manager" in one session and "Sarah" in another resolve to one person on the server.
COMPACTION
LangChain 1.x: SummarizationMiddleware summarizes older messages past a threshold you set.
With Synap: Automatic compaction per conversation, with a validation score returned on every pass.
RETRIEVAL LATENCY
LangChain 1.x: Depends on your store and embedding setup.
With Synap: in-conversation reads at an asserted P75 under 15ms from an in-process cache; cold retrieval targets P95 450ms.
LONG-TERM RECALL
LangChain 1.x: Depends on what your code writes and how it searches.
With Synap: 92% 95.6% on LongMemEval and 93.2% on LoCoMo (open harness; LongMemEval with Gemini 3.8 Flash as answer model and gpt-4o as judge, LoCoMo with gpt-5-mini as answer model and judge).
FAILURE HANDLING
LangChain 1.x: A store or retriever exception propagates unless you add a fallback.
With Synap: The handler logs and never raises. The retriever and the tools raise SynapIntegrationError, which one with_fallbacks call turns into an empty result.
USER SCOPING
LangChain 1.x: A namespace scheme you design, with the user ID passed through runtime context.
With Synap: user_id on every component, conversation_id per conversation, and customer_id on multi-tenant (B2B) instances.
What Production Teams Gain
Cross-session continuity. Your user chats on Monday, returns on Wednesday in a new thread. The handler recorded Monday's turns, Synap extracted what mattered, and SynapRetriever surfaces those facts before Wednesday's first reply. Your checkpointer still owns the messages inside each thread.
Accuracy that ships. Synap scores 92% 95.6% on LongMemEval and 93.2% on LoCoMo, benchmarks that measure whether agents recall facts across long, multi-turn conversations spanning multiple sessions, reproduced on our open harness with Gemini 3.8 Flash as answer model and gpt-4o as judge for LongMemEval, and gpt-5-mini as answer model and judge for LoCoMo.
Token efficiency. Synap's Agentic Compaction keeps the working context bounded: it triggers at 3,000 tokens, 10 messages or 5 minutes idle, compresses toward a 1,500-token target while keeping the last three conversation pairs verbatim, and returns a validation score and a preserved-facts count on every pass. Re-sending the full history grows token cost quadratically with conversation length; validated compaction keeps it close to linear.
Latency that does not block. In-conversation reads come from a cache Synap pre-fetches into your own process, at an asserted P75 under 15ms; a cold retrieval targets P95 450ms. A failed recording is logged and your chain still returns its answer.
Entity resolution. "My manager" on Monday and "Sarah" on Wednesday resolve to one person on the server, so your chain does not have to.
Scoping. Each component takes its IDs as constructor arguments. A B2C instance takes user_id alone and rejects customer_id; a B2B instance requires it.
How to Get Started
Setup
Install the package alongside LangChain and your model provider. It needs Python 3.11 or later:
pip install maximem-synap-langchain langchain langchain-openai
Configure your API key. Generate one from the Synap Dashboard.
.env
SYNAP_API_KEY=synap_your_key_here
OPENAI_API_KEY=your-openai-api-key
Then initialize the SDK once at application startup:
from maximem_synap import MaximemSynapSDK
sdk = MaximemSynapSDK() # picks up SYNAP_API_KEY from env await sdk.initialize()
See SDK Initialization for the full lifecycle and configuration options.
Remember a user across two conversations. The chain below retrieves what Synap knows about the user before each reply, and the handler records every turn so the next conversation has something to retrieve:
import uuidfrom langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import RunnableLambda, RunnablePassthrough from langchain_openai import ChatOpenAI from synap_langchain import SynapCallbackHandler, SynapRetriever
retriever = SynapRetriever(sdk=sdk, user_id="alice", mode="fast", max_results=8) safe_retriever = retriever.with_fallbacks([RunnableLambda(lambda _: [])])
def format_docs(docs): return "\n".join(f"- {doc.page_content}" for doc in docs)
prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant.\n\nWhat you know about this user:\n{memory}"), ("human", "{question}"), ])
chain = ( RunnablePassthrough.assign( memory=RunnableLambda(lambda x: x["question"]) | safe_retriever | format_docs ) | prompt | ChatOpenAI(model="gpt-4o") )
async def ask(question: str, conversation_id: str): handler = SynapCallbackHandler( sdk=sdk, conversation_id=conversation_id, # must be a valid UUID user_id="alice", # add customer_id="acme" on a B2B instance ) return await chain.ainvoke({"question": question}, config={"callbacks": [handler]})
# Mondayawait ask("We agreed to ship the Q2 roadmap on 14 June.", str(uuid.uuid4()))
# Wednesday, a new conversation
reply = await ask("Remind me what we agreed on for the Q2 roadmap.", str(uuid.uuid4())) print(reply.content)
Build one handler per conversation. Recording failures are logged at ERROR level and never propagate to your chain, so your application keeps running even if Synap is unreachable. The retriever raises SynapIntegrationError instead, and the with_fallbacks line is what turns an outage into an empty memory list.
Memory Is Infrastructure
LangChain gave agent builders a standard way to persist state: a checkpointer for the thread and a store for everything that outlives it. Deciding what goes into the store, resolving who a sentence is about and retiring a fact once it stops being true is a different problem.
Teams either write that logic on top of the store themselves, or they plug in a system built for it. The payoff is the same: an agent that gets more useful with every conversation, for customers who stop repeating themselves.
This is why memory is infrastructure, not a feature.
Start building LangChain agents that remember across sessions: https://synap.maximem.ai
Synap pricing is usage-based. You pay for memory operations: storage, retrieval, compaction. No per-seat or per-framework surcharge. Starter plan: $19/month at launch pricing (list $49). Every new account gets about $10 in free credits to test before committing. See full pricing at https://synap.maximem.ai/pricing.
Related Posts
- What Is Agentic Context Management?
- The Real Cost of DIY Agent Memory
- How to Add Persistent Memory to a LangGraph Agent
- Skills Are the New Microservices
Frequently Asked Questions
Does LangChain have long-term memory built in?
It has the storage for it. LangChain 1.x uses a checkpointer for thread memory and a LangGraph store for memory across conversations, and both persist on a database. Neither decides what is worth remembering or resolves entities.
How is Synap different from a LangGraph store with semantic search?
A store returns the documents your code wrote, ranked by vector similarity. Synap extracts memories from recorded conversations, types them, links entities and handles retractions, then returns them through a standard retriever.
What is the latency overhead?
In-conversation reads come from a cache pre-fetched into your process, at an asserted P75 under 15ms; a cold retrieval targets P95 450ms. Callback recording is awaited inside LangChain's callback system and never raises into your chain.
What happens when Synap is unreachable?
SynapCallbackHandler logs an error and your chain continues. SynapRetriever and the two tools raise SynapIntegrationError, so wrap the retriever with with_fallbacks if you want an empty result instead. The package is at version 0.3.1 and marked alpha on PyPI, so pin the version you test against.
How does pricing work?
Usage-based. Storage, retrieval, and compaction are metered separately. No per-seat or per-framework fee. Starter plan is $19/month at launch pricing (list $49), and new accounts get about $10 in free credits. See
https://synap.maximem.ai/pricing.



