AI Agent Memory Explained: Short-Term Context, Long-Term Recall and What to Store

AI agent memory explained: short-term context lives in a checkpointer, long-term recall in a store. How LangGraph, LangMem, Mem0 and Zep handle each.

By Galactic News Editorial · Published 2026-11-16T10:36:33+00:00 · Updated 2026-11-16T10:36:33+00:00

AI agent memory explained: short-term context and long-term recall diagram

AI Agent Memory Explained: Short-Term Context, Long-Term Recall and What to Store

An agent that forgets is a chatbot with tools. It asks the same question twice, repeats work it already did, and treats every session as a first meeting. Memory is what turns a stateless model call into an agent that learns: it remembers the conversation, the user's preferences, and the decisions from last week. This guide explains the two kinds of memory, how the main frameworks store them, and what belongs in each.

AI Agent Memory Explained in One Table

AspectShort-term memoryLong-term memory
ScopeOne conversation threadAcross threads and sessions
What it holdsMessage history, current stateUser facts, preferences, decisions
LangGraph mechanismCheckpointerStore
Survives restartOnly with a database-backed checkpointerYes, by design
Main riskContext window overflowStale or wrong facts
Typical backendPostgres or MongoDB checkpointerPostgres store, vector store, or memory service

The split is the first decision in any agent design. Short-term memory answers the question 'what are we talking about right now?' Long-term memory answers 'what do I know about this user?' They need different storage, different write rules, and different cleanup.

Short-Term Memory: Checkpointers Keep the Thread

In LangGraph, short-term memory is thread-level persistence. The agent's state — messages, tool results, intermediate values — is saved after each step by a checkpointer, keyed by thread. Pass the same thread id on the next call and the conversation resumes where it stopped. That covers multi-turn chat, human-in-the-loop pauses, and recovery after a crash.

The checkpointer choice is a durability choice. InMemorySaver keeps checkpoints in RAM, so they vanish when the process restarts. It is fine for a demo and wrong for production. In production, use a database-backed checkpointer such as PostgresSaver or a MongoDB checkpointer. LangChain's docs note that thread ids should stay under 255 characters, and that database-backed persistence needs migrations run as a deployment step.

Checkpointing alone does not solve the context window. A long thread grows until it no longer fits the model's input. LangChain's docs list four ways to manage it: trim messages, delete messages, summarize earlier messages into a running summary, and manage checkpoints directly. Summarizing is the most common production choice: keep a summary key in state alongside the messages, and update the summary every few turns. Trimming is cheaper and loses detail. Pick based on how much the agent needs to remember verbatim.

Long-Term Memory: Stores and Memory Layers

Long-term memory lives outside the thread. In LangGraph it is a store: a namespaced key-value database of JSON documents, where the namespace works like a folder and the key like a file name. The developer decides what to write, when to update it, and how to search it. A store can run with semantic search, so the agent retrieves memories by meaning rather than exact keys. In LangChain 1.x, both the checkpointer and the store are passed to create_agent.

A bare store holds exactly what the developer writes. It does not extract facts from a conversation, update them when they change, or build a user profile. For that, add a memory layer. LangMem is LangChain's own library for this: it extracts memories from conversations into the store, with background consolidation. Mem0 takes a different approach — an extractor model pulls salient facts from messages, deduplicates them, and stores them in a vector store, with add and search calls scoped by user, agent, and run. Zep builds a temporal knowledge graph with its Graphiti engine: facts are edges with valid-from and valid-until times, so when a new fact contradicts an old one, the old one is invalidated rather than overwritten, and its history is kept.

The older LangChain memory classes, such as ConversationBufferMemory, are deprecated and due for removal. Current code should use a checkpointer for conversation history and a store for durable memory.

What to Store — and What to Leave Out

Store facts that stay true across sessions and change what the agent should do. User preferences belong here: language, tone, tools the user likes, the level of detail they want. Durable facts belong here: the user's role, their project, the decisions made in earlier sessions. Goals and constraints belong here too, because they shape future answers.

Leave out anything that expires fast. A fact that is true today and false next week needs a validity window or it becomes a lie the agent repeats with confidence. Leave out raw transcripts: they cost tokens on every retrieval and carry more detail than the agent needs. Store the extracted fact instead. Leave out secrets entirely: passwords, API keys, tokens, and credentials never belong in memory, and neither does sensitive personal data without a clear purpose and the user's consent.

Every stored fact needs three things: a source, a time, and a way to delete it. The source says where the fact came from. The time says when it was learned. The delete path matters for privacy rules and for trust: a user who cannot correct or erase what the agent remembers will stop telling it anything.

A Minimal Memory Setup in Five Steps

Step 1: Choose the checkpointer. Install a Postgres checkpointer, run its migrations, and pass it to create_agent with a stable thread id per conversation.

Step 2: Add a store for long-term memory. Create namespaces per user, and write only durable facts — preferences, roles, decisions — never raw transcripts.

Step 3: Add summarization for long threads. Keep a summary key in state, update it every few turns, and trim the raw message list so the thread stays inside the context window.

Step 4: Add an extraction step after each turn. Run the conversation through LangMem or Mem0, and write the extracted facts into the store with a timestamp and a source note.

Step 5: Check retrieval before shipping. Ask the agent questions that depend on stored facts, and confirm it recalls the right ones. Test the delete path too: remove a fact and confirm it stays gone.

Bottom Line

Short-term memory is the thread, saved by a checkpointer. Long-term memory is the store, filled by an extraction layer such as LangMem, Mem0, or Zep. The difference that matters most is the write policy: short-term memory is automatic, long-term memory is a decision. Store durable facts with a source and a timestamp, give every fact an expiry or a delete path, and never store secrets. An agent that remembers the right things — and forgets the rest on purpose — is the one users come back to.