[supermemory](https://supermemory.ai/) · Guides

# How do I add long-term memory to a LangChain agent?

Reviewed November 10, 2026 [Docs for this setup](https://supermemory.ai/docs/integrations/langchain) 

LangChain gives you two building blocks. A checkpointer keeps one thread's messages, which is short-term memory. The LangGraph Store is a key-value store you read and write yourself, which gives memory across threads. Both store exactly what you put in; neither extracts facts from a conversation, updates them when they change, or keeps a profile of the user. For that, add a memory layer: supermemory (a profile call and a search call before the model, an add call after, in Python or TypeScript), LangMem (LangChain's own extraction library on top of the Store), Mem0 or Zep. The pattern is the same in a chain and in a LangGraph node.

## What memory does LangChain have built in?

* **Checkpointers** (`InMemorySaver`, `PostgresSaver`) save a graph's state after each step, keyed by thread. That is how a conversation resumes. It is one thread's history, not knowledge about the user.
* **The Store** (`InMemoryStore`, `PostgresStore`) is a namespaced key-value store available inside nodes and tools, for memory across threads; in LangChain 1.x both are passed to `create_agent(checkpointer=…, store=…)`. You decide what to write, when to update it and how to search it.
* **LangMem** is LangChain's library for extracting memories from conversations into the Store, with background consolidation. It is Python and MIT, you host the Store it writes to, and it has had no release since October 2025.

If what you want is "the agent knows this user and remembers earlier conversations" without writing the extraction and updating logic, that is what a memory API does.

## How do I add supermemory to a LangChain agent?

1. Install the SDK alongside LangChain and set `SUPERMEMORY_API_KEY` from the console.
2. Before the model call, fetch the user's profile and the memories relevant to the message. The profile has `static` facts (who the user is) and `dynamic` context (what they are doing now).
3. Put both into the system prompt and run the chain.
4. After the reply, add the exchange. supermemory extracts the memories, updates ones that changed and refreshes the profile; the next call sees them.

```
pip install langchain langchain-openai supermemory
```

```
from langchain_openai import ChatOpenAI
from langchain_core.messages import SystemMessage, HumanMessage
from supermemory import Supermemory

llm = ChatOpenAI(model="gpt-5")
memory = Supermemory()  # reads SUPERMEMORY_API_KEY

def chat(user_id: str, message: str) -> str:
    profile = memory.profile(user_id).profile
    related = memory.search(user_id, query=message, threshold=0.5).results

    system = (
        "About this user:\n" + "\n".join(m.memory for m in profile.static)
        + "\n\nCurrent context:\n" + "\n".join(m.memory for m in profile.dynamic)
        + "\n\nRelevant memories:\n" + "\n".join(r.memory for r in related)
    )
    reply = llm.invoke([SystemMessage(content=system), HumanMessage(content=message)]).content

    memory.add(user_id, content=f"User: {message}\nAssistant: {reply}")
    return reply
```

The namespace is the first argument of every call. Use a stable identifier per user, team or tenant; each namespace has its own memories and its own profile, and a request never crosses one.

## How does it work in a LangGraph node?

The same three calls, inside the node that calls the model. Keep the checkpointer for the thread's messages and let supermemory hold what lasts beyond the thread.

```
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import InMemorySaver

def agent(state: State):
    user_id = state["user_id"]
    query = state["messages"][-1].content
    profile = memory.profile(user_id).profile
    related = memory.search(user_id, query=query).results
    system = build_system_prompt(profile, related)
    reply = llm.invoke([SystemMessage(content=system), *state["messages"]])
    memory.add(user_id, content=f"User: {query}\nAssistant: {reply.content}")
    return {"messages": [reply]}

graph = StateGraph(State)
graph.add_node("agent", agent)
graph.add_edge(START, "agent")
graph.add_edge("agent", END)
app = graph.compile(checkpointer=InMemorySaver())
```

The [LangGraph page in the docs](https://supermemory.ai/docs/integrations/langgraph) has a full support-agent graph with retrieve, categorise, respond and store nodes.

## Which memory layers work with LangChain?

| Option          | What it stores                                                 | Extracts and updates facts         | User profile                               | Where it runs                                                           |
| --------------- | -------------------------------------------------------------- | ---------------------------------- | ------------------------------------------ | ----------------------------------------------------------------------- |
| LangGraph Store | Whatever you write, as key-value items                         | No, you write the logic            | No, unless you build it                    | Your infrastructure                                                     |
| LangMem         | Memories it extracts, into the Store                           | Yes, with background consolidation | Can maintain a profile document you define | Your infrastructure; Python; last release October 2025                  |
| Mem0            | Memories it extracts, per user; used through the mem0ai SDK    | Yes                                | User memories you query                    | Open source (Apache 2.0), self-hosted, or Mem0 platform                 |
| Zep             | A temporal knowledge graph of facts; the zep-langgraph package | Yes                                | Facts about the user from the graph        | Graphiti is open source (Apache 2.0); Zep Cloud hosted or in your cloud |
| supermemory     | Memories it extracts, plus documents                           | Yes, with automatic forgetting     | Yes, static and dynamic, one call          | Hosted, local binary, or your cloud on Scale and Enterprise             |

## Does it work with LangChain.js?

Yes. The `supermemory` npm package has the same three calls: `supermemory.profile(namespace)`, `supermemory.search(namespace, { query })` and `supermemory.add(namespace, { content })`. Wire them around the model call in the same places.

## Questions

### Does LangChain have long-term memory built in?

LangGraph has a Store for memory across threads and checkpointers for a thread's history, and LangMem adds extraction on top of the Store. The Store holds what you write; it does not extract or update facts for you.

### Does supermemory work with LangGraph?

Yes. The same profile, search and add calls run inside a node; the docs include a complete support-agent graph.

### Is there a langchain-supermemory package?

No. The supermemory SDK is used directly, in Python or TypeScript, around the model call. Nothing in LangChain needs to be subclassed.

### How do I keep users' memories apart?

Use one namespace per user as the first argument of every call. Namespaces are hard boundaries; a search never returns another namespace's memories.

### Can the agent read documents as well as memories?

Yes. Files, URLs and text added to a namespace are searchable with the same search call, so one agent can use conversation memory and documents together.

supermemory facts from the LangChain and LangGraph pages in the supermemory docs. LangGraph Store and checkpointers from docs.langchain.com; LangMem from github.com/langchain-ai/langmem and PyPI. Mem0's LangChain guide from docs.mem0.ai; Zep's zep-langgraph package from help.getzep.com and PyPI. Checked November 10, 2026\. The setup steps restate the [docs page for this integration](https://supermemory.ai/docs/integrations/langchain); when the two differ, the docs are current.

[All guides](https://supermemory.ai/guides/)
