An agent without memory repeats the same questions and loses context between sessions. LangGraph solves this with two distinct mechanisms: checkpointers for short-term memory and stores for long-term memory.
It's a common mistake to treat "memory" as a single concept. LangGraph explicitly distinguishes between short-term memory — the history of the current conversation, tied to a `thread_id` — and long-term memory — facts or user preferences that must persist across different conversations, even after the `thread_id` changes. The former is solved with checkpointers; the latter with LangGraph's `Store`.
For development and testing, `MemorySaver` keeps state in the process's memory. For production, you need real persistence:
With `PostgresSaver`, if the process restarts or the user closes and reopens the conversation with the same `thread_id`, the graph recovers the exact state where it left off, including the full message history and any other key in the defined state.
When you need to remember information about the user beyond a single conversation — their name, preferences, a summarized purchase history — you use a `Store`, indexed not by `thread_id` but by a `namespace` that belongs to the user:
When compiling the graph with `builder.compile(checkpointer=checkpointer, store=store)`, any node can declare the `store` parameter in its signature and LangGraph injects it automatically at runtime.
A conversation with hundreds of messages eventually exceeds the context window or triggers unnecessary costs. The standard pattern is a node that, when the history exceeds a threshold, summarizes it and replaces the old messages with the summary:
`RemoveMessage` is a special type that, combined with LangGraph's message reducer, removes specific messages from the state by id, letting you prune history without losing the most recent turns — usually the most relevant ones for the immediate response.
In real deployments we use `PostgresSaver` for the transactional state of the active conversation (with a reasonable TTL, since not every thread needs to live forever) and a separate `Store` — sometimes backed by the same database, sometimes by a vector store when long-term memory needs semantic search over accumulated preferences — for what must survive across sessions. Mixing both concepts into a single ad-hoc table is the most common cause of "phantom memory" bugs we've seen in audits: information from one conversation leaking into another because the same `thread_id` got reused for different users.
Carlos Montiel is an enterprise AI solutions architect. He implements LLMs, Agents, RAG, and orchestrators for companies across Guatemala and Latin America. Reach out for a consultation.
Contact Carlos Montiel