Agent memory systems
In-session state, cross-session facts, and external stores — what each memory layer solves, and the pitfalls they share.
What this guide covers
Agent memory means letting the next call know what happened in this one. Without memory every turn is a first meeting; with too much memory the context bursts. In engineering, view it in three layers: in-session state, cross-session facts, external stores. The three layers differ in where they persist, how long they live, how they are read and written — and in how they go wrong.
Layer one: in-session state
The most common need: multi-turn conversations must not lose the thread. OpenAI official text: sessions provide "built-in session memory to automatically maintain conversation history across multiple agent runs".
The mechanism is plain: before each turn, history is fetched and prepended to the input; after each turn, newly produced entries (user input, replies, tool calls) are stored back into the session. Under the hood are local sessions such as SQLite, out of the box.
LangGraph calls this kind of capability a checkpointer. The official docs split it into two by scope: the checkpointer manages the single-thread graph-state snapshot, the store manages cross-thread application-defined data. The first keeps "this phone call from dropping", the second remembers "all calls from this user".
Pitfall one: the in-memory version does not persist. LangGraph's official troubleshooting says plainly: MemorySaver and InMemorySaver keep checkpoints in RAM — restart the process and everything is gone. Production should use persistent backends like PostgresSaver / SqliteSaver.
Pitfall two: checkpoints grow without bound. In long conversations checkpoints pile up; the official advice is periodic cleanup or a retention policy — otherwise latency and storage rise together.
Layer two: cross-session facts
Sessions end, facts must remain: user preferences, project decisions, common settings. Mem0 splits this road in two: extraction and retrieval.
On add, Mem0 extracts durable facts from the messages and stores them. By default what is stored is distilled facts, not the raw message text; to keep verbatim text you must explicitly turn inference off. Before the next model call, search injects the most relevant few into the prompt.
The official docs stress two disciplines: retrieval must filter by dimensions like user_id / agent_id so different users' memories do not mix; when a fact goes stale, update / delete it explicitly — automatic extraction only adds, never revises.
Letta takes another road: the agent directly manages a set of memory files. The current MemFS is a git-backed memory file system the agent can read, write, and reorganize, with memory shared across its conversations.
It also ships dreaming: a background sub-agent periodically reviews conversations and consolidates useful experience into memory, never interrupting the work at hand. In the official CLI, /remember teaches explicitly, /memory inspects, /doctor audits memory structure and token footprint.
Pitfall three: add-only accumulation breeds stale facts. The user moved long ago, yet two cities still live in the memory at once. Extraction-based memory needs a correction process.
Layer three: external stores
What does not fit in the context — do not force it in, attach it outside. The official MCP memory server stores entities and relations in a knowledge graph, queried on demand; vector stores and key-value stores are also commonly used for this.
The key at this layer is not "how much was stored" but "does recall hit": which signal dominates retrieval — relevance, recency, entity matching — directly decides recall quality.
The MemGPT paper (arXiv 2310.08560) is one origin of this route. It proposes virtual context management: imitating operating-system memory hierarchies, swapping content in and out of a finite context window so the model appears to have a huge memory. The paper validated this on document analysis and multi-session chat.
Letta's memory blocks (labeled blocks like human / persona) are the engineering version of the idea: memory chunked, labeled, editable. From paper to product, memory's shape evolved from "memory hierarchy" to "the agent's own file system".
Where the layers end
An easy confusion: does a summary count as memory? Compressing a long conversation into a summary and continuing is compression, not memory — it still lives only in the current session and is gone when the session closes.
To decide which layer something belongs to, ask one question: after the process restarts, is it still there? Still there → layer two or three; gone → layer one.
Shared pitfalls
- Memory leakage: sensitive information stored verbatim into long-term memory, then recalled back into context.
- Crossed users: without user_id filtering, user A's memory is recalled in user B's session.
- Silent rewriting: automatic updates overwrite old facts and nobody can say what changed.
- Silent token bloat: a too-loose recall policy stuffs a pile of "relevant" memories into every turn.
The acceptance criterion for a memory system is a single line: what should be remembered can be found; what should not be cannot be recalled.
Sources
| Source | URL |
|---|---|
| LangGraph official docs · Persistence (direct fetch 200 on 2026-10-30) | https://docs.langchain.com/oss/python/langgraph/persistence |
| OpenAI Agents SDK official docs · Sessions (direct fetch 200 on 2026-10-30) | https://openai.github.io/openai-agents-python/sessions/ |
| Mem0 official docs · How Mem0 Works (direct fetch 200 on 2026-10-30) | https://docs.mem0.ai/core-concepts/how-it-works |
| Letta official docs · Memory & dreaming (direct fetch 200 on 2026-10-30) | https://docs.letta.com/configuration/memory/ |
| MemGPT paper (arXiv 2310.08560, abstract page direct-fetched 2026-10-30) | https://arxiv.org/abs/2310.08560 |
Source snapshot: 2026-10-30; item-specific rechecks and their scope are recorded in the text or source notes. Features and terms may change; check the original sources before use.