An LLM's context window is not memory — it's working memory that resets between sessions. The gap between "toy demo that forgets everything after the browser tab closes" and "production agent that remembers what a user prefers three months later" is a dedicated memory architecture. In 2026 this has matured from ad-hoc prompt-stuffing into a distinct engineering discipline with its own frameworks, benchmarks, and failure modes.
Short-term vs. long-term memory
Short-term memory holds the current conversation: the last few turns, the active task, immediate context. Long-term memory persists across sessions, scales to millions of stored memories, and needs to retrieve relevant context in milliseconds (Redis). Memory-enhanced agents combine both — short-term for real-time responsiveness, long-term for deeper understanding accumulated over extended use (Let's Data Science).
Treating memory as a separate architectural component rather than "a longer prompt" is the core shift: the model itself stays stateless between calls, and an external system decides what gets written, what gets retrieved, and what gets injected into context before each call.
The three memory scopes
The field has converged on three standard scopes, borrowed loosely from cognitive science terminology (Atlan):
- Episodic memory — specific past interactions ("the user asked about refund policy on March 3rd and was frustrated by the wait time").
- Semantic memory — facts and stable preferences ("the user's company uses Stripe for billing").
- Procedural memory — learned behaviors and rules the agent should apply going forward ("always confirm order ID before processing a return").
Most production systems only implement the first two well; procedural memory (the agent actually changing its own behavior from past experience) remains the least mature of the three.
The standard processing pipeline
Regardless of vendor, most long-term memory systems follow the same four stages (Let's Data Science):
- Chunk the raw interaction text into storable units.
- Embed and index — convert into dense vectors, store in a vector database for similarity search.
- Retrieve relevant pieces at query time using semantic similarity, keyword matching, and entity matching.
- Consolidate — decide what's worth keeping long-term versus discarding as noise.
At the start of a new session, relevant memories are retrieved and injected into the context window before the model generates a response (Let's Data Science).
Leading frameworks compared
Five frameworks dominate current production usage, each taking a genuinely different architectural bet (Atlan):
| Framework | Core approach | Deployment | Best fit |
|---|---|---|---|
| Mem0 | Vector-based semantic recall, LLM-driven ADD/UPDATE/DELETE ops | Managed service, REST API, any stack | Framework-agnostic teams |
| Zep (Graphiti) | Temporal knowledge graph | Self-hosted or managed | Facts that change over time |
| LangGraph (LangMem) | Checkpoint-based persistence | Sub-package of LangChain | Teams already on LangGraph |
| Letta (MemGPT) | Self-editing memory blocks | Self-hosted | Agents that manage their own memory |
| LangChain ConversationBufferMemory | Raw buffer, no consolidation | In-process | Prototyping only |
Mem0 stores memories across three isolated scopes — user-level (preferences/history), session-level (current conversation), and agent-level (agent-specific knowledge) — and uses an LLM to decide whether an incoming fact should be added, update an existing record, delete a stale one, or be treated as a no-op against existing vector-embedded memories (Mem0 blog). In April 2026, Mem0 shipped a token-efficient memory algorithm using single-pass hierarchical extraction and multi-signal retrieval, aimed directly at reducing the token overhead of memory injection (Atlan).
Zep's differentiator is genuinely structural, not marketing: a temporal knowledge graph means the system can represent that a fact was true at one point and superseded later — useful for agents tracking evolving state (account status, project phase) rather than static preferences (Atlan).
The deployment split matters operationally: Mem0 is a standalone managed service usable from any agent stack via REST API, while LangMem is tightly coupled to LangChain/LangGraph and requires your team to run its own storage backend (Atlan).
When memory infrastructure isn't worth it
Not every agent needs a dedicated memory stack. For single-user agents with fewer than roughly 500K tokens of accumulated history and fewer than 10 sessions, the operational cost of maintaining a Mem0 + vector database stack can exceed the cost of just passing more raw history into a long-context model directly (Mem0 blog).
Note
A minimal memory write/retrieve loop
# Simplified Mem0-style memory loop
def handle_turn(user_id, message, agent):
memories = memory_store.search(query=message, user_id=user_id, limit=5)
context = format_memories(memories)
response = agent.generate(
system_prompt=BASE_PROMPT + context,
user_message=message,
)
# LLM-driven decision: ADD / UPDATE / DELETE / NOOP
memory_store.extract_and_update(
user_id=user_id,
conversation=[message, response],
)
return response
The extract-and-update step is where most of the engineering complexity lives: naively appending every turn as a new memory record causes uncontrolled growth and retrieval noise. Production systems run an LLM pass specifically to decide whether new information should overwrite, merge with, or coexist alongside existing memories.
Governance and safety risks
Memory that evolves automatically introduces a failure class that stateless LLM calls don't have: an agent can accumulate incorrect or stale beliefs about a user and act on them confidently. Recent research proposes explicit governance frameworks — such as Stability and Safety Governed Memory (SSGM) — specifically to manage risk from evolving memory in LLM agents, including provenance tracking so an agent's memory is auditable, not a black box (arXiv). A related failure mode, provenance-role collapse, occurs when long-term agents lose track of where a memory came from (user statement vs. tool output vs. agent inference) and start treating inferred facts as ground truth (arXiv).
Warning
Retrieval quality over storage volume
The temptation with memory systems is to store everything and rely on retrieval to surface the right thing at query time. In practice, retrieval quality — not storage volume — is the bottleneck. Systems combining semantic similarity with keyword and entity matching outperform pure vector similarity search, particularly for queries referencing specific names, dates, or IDs that embeddings alone handle poorly.
Actionable takeaway
Start by scoping memory into the three standard categories (episodic, semantic, procedural) and be honest about which your agent actually needs — most only need episodic and semantic. Choose Mem0 if you want a managed, framework-agnostic service with LLM-driven consolidation; choose Zep if your data genuinely has a temporal dimension (facts that change and need history); skip a dedicated memory framework entirely if your per-user history is small enough to fit in a long context window. Whatever you choose, build in provenance tracking from day one — retrofitting an audit trail onto an agent that has already accumulated months of unaudited memory writes is far more expensive than designing it in up front.
Sources: Redis: Long-Term Memory Architectures for AI Agents, Let's Data Science: AI Agent Memory Architecture, Mem0: State of AI Agent Memory 2026, Atlan: Best AI Agent Memory Frameworks 2026, arXiv: Governing Evolving Memory in LLM Agents (SSGM), arXiv: Mitigating Provenance-Role Collapse
Get new posts as they publish
No spam — just the next post, straight to your inbox.