16.5 Long-term Memory for Agents
An agent without memory feels capable for a few minutes and forgetful after that. It may solve the current step, but it cannot build a stable relationship with a user, reuse prior decisions, or accumulate useful operating rules. That is why long-term memory matters. Not because “persistent memory” sounds futuristic, but because many real tasks are impossible if every session starts from zero.
It helps to compare this to a good engineer joining a long-running incident. The first hour is spent reconstructing context: what changed, what was already tried, what constraints still matter. Memory systems exist to reduce that reconstruction tax.
For developers, the practical payoff is straightforward: a coding agent can remember repository conventions, a support agent can remember durable customer preferences, and an operations agent can remember which recovery steps already failed. Without that separation between short-lived context and durable memory, the system repeatedly pays the cost of reconstructing context.
1. A Practical Memory Contract
Before choosing a vector database, graph store, or memory framework, define what a memory record actually contains. A useful long-term memory entry usually needs:
- content: the fact, event, preference, or rule itself
- type: fact, episode, preference, or procedure
- source: user-provided, tool-derived, model-inferred, or copied from another agent
- confidence: how strongly the system should trust it
- last updated: when the claim was last refreshed
- retention class: how long it should live and whether it must be deletable
This may sound mundane, but it is one of the clearest differences between toy memory and production memory.
2. Memory Is More Than a Vector Store
Raw-history retrieval is an important baseline. More structured storage should earn its complexity through measured task gains and operational requirements; retrieval alone still needs provenance, access control, updates, and deletion.
A useful design vocabulary distinguishes three layers:
- working memory: the active context window
- episodic memory: specific past events, actions, and outcomes
- semantic or procedural memory: stable facts and reusable rules
The engineering challenge is deciding what belongs in each layer and when information should move between them.
3. Write, Manage, Read
A practical memory loop has three parts:
- Write: decide what is worth storing
- Manage: deduplicate, update, compress, or expire it
- Read: retrieve the right memory at the right time
This sounds obvious, but most failures happen here.
Common write errors:
- storing too much
- storing low-confidence inferences as facts
- recording temporary state as if it were long-term truth
Common read errors:
- retrieving loosely related but distracting memories
- returning stale facts after the world has changed
- mixing user-provided facts with agent-generated guesses
4. Choosing a Memory Substrate
Vector Memory
Vector retrieval is a reasonable first step. It works well for semantically similar recall, summaries, and free-form history search.
Structured Memory
For more relational tasks, teams often add lightweight structure:
- key-value stores for stable facts
- event logs for episodic traces
- graphs for entities and relationships
This does not mean every agent needs a full knowledge graph. It means memory quality often improves once the system distinguishes “facts,” “events,” and “rules” instead of storing everything as the same kind of text chunk.
Latent or Model-Internal Memory
Research also explores memory that is closer to the model’s hidden-state dynamics than to a traditional database. This is an interesting direction, but it remains much less operationally mature than the retrieval-based memory systems teams commonly deploy today.
Recent work such as HippoRAG also shows that graph-structured memory can improve multi-hop recall while staying cheaper than iterative retrieval strategies [3]. The practical takeaway is not that every agent needs a graph, but that memory substrate should follow the task: semantic recall, event replay, and relational reasoning are different jobs.
What Recent Memory Research Actually Teaches
Several influential papers point to different design lessons rather than one single winning architecture.
- Generative Agents emphasizes full natural-language event logs, retrieval by recency, relevance, and importance, plus higher-level reflection summaries [1]. The lesson is that raw event storage and reflective abstraction are different memory operations.
- MemoryBank adds an explicit forgetting-and-reinforcement mechanism inspired by the Ebbinghaus forgetting curve [4]. The lesson is that long-term memory quality depends on retention policy, not just retrieval quality.
- MemGPT treats memory as a hierarchy with active context and slower external stores [2]. The lesson is that memory is partly a scheduling problem: what stays in the working set and what gets paged out.
- HippoRAG highlights that graph-structured memory can help multi-hop recall without requiring repeated retrieve-and-rerank loops [3]. The lesson is that relational reasoning often benefits from a different substrate than semantic similarity search.
5. The Hard Problems: Staleness, Source, and Privacy
The hardest memory problem is not storing information. It is knowing when stored information should stop dominating future behavior.
Staleness
If a user once said “I work in New York” and later says “I just moved to Chicago,” the system needs to update its active truth without destroying historical context.
Source Tracking
Agents also need provenance. A memory written by the user, inferred by the model, or copied from another agent should not be treated identically.
Privacy
The more successful a memory system becomes, the more it turns into a privacy system. Teams need retention policies, deletion paths, and a clear answer to where memory is stored and who can retrieve it.
October Research: Test the Write Path Separately
Research snapshot as of 2026-10-18. Hy-Memory-30B-A3B trains a memory writer through on-policy distillation and attributed rewards over policy-written banks. The paper evaluates fixed 20% benchmark subsamples across several harnesses; attribution is evidence-based, not a counterfactual proof that a particular write caused a correct answer [5]. A specialized writer is not a general-purpose agent, and its benchmark average does not certify privacy or deletion correctness.
FEB-30 takes a complementary approach: it generates documents from known fact-evolution trajectories and inspects the store after each ingestion. Its 30 trajectories expose cases where correct answers mask broken memory, or retrieval failures obscure correct memory [6]. This is a diagnostic benchmark, not a representative production failure rate.
An engineering evaluation should therefore separate three layers:
| Layer | Controlled check | Failure it can isolate |
|---|---|---|
| Write/update | Inspect the bank after each event | Duplicate, stale, unsupported, or wrongly superseded facts |
| Retrieval | Query a known-correct bank | Missing evidence, wrong entity, or authorization leak |
| Answer/action | Supply verified evidence to the agent | Unsupported synthesis or unauthorized tool effect |
For example: a user moves from New York to Chicago and later corrects the move date. Test current residence, historical residence, effective date, source identity, and deletion after each event. A final answer of “Chicago” cannot prove all five are correct.
For learning-based writers, inherit the complete RLVR contracts in 15.5 and additionally pin the memory schema, bank snapshot/hash, writer and reader revisions, chunk boundaries, reward probes, storage penalty, and deletion policy. Checkpoint the exact persistent bank together with its rollout cursor. Monitor storage growth, unsupported additions, stale-fact retention, update/delete failures, and answerability by domain. Do not promote an apparent QA gain if any critical authorization or deletion slice regresses.
6. Interactive Visualizer: Memory Consolidation
The visualizer below shows the intuition behind consolidation: temporary observations do not all belong in the same long-term store, and memory quality depends heavily on how the system routes information.
Memory preserves claims and scope
“I am moving my Acme data pipeline to Snowflake. Always use Python 3.11.”
Graph claim
No derived recordRetrieval text
No derived recordPreference
No derived record7. Practical Takeaway
Long-term memory for agents is best viewed as a retrieval and data-management problem wrapped around an LLM. Vector stores help, but production-grade memory requires policy: what to store, how to update it, how to track confidence, and when to forget.
In the next section, we move from memory to reliability: how do we recover when an agent loop goes wrong, and what guardrails make these systems safe enough to operate?
October 22 Research: Preserve a Raw-history Baseline
As of 2026-10-25, Bao et al.’s Raw-RAG preprint evaluates dense retrieval and reranking over raw conversation history across four memory benchmarks. It reports first place among compared memory systems in six of seven benchmark/model settings; full-context references are a separate comparison [7]. The result is bounded by its readers, evidence budgets, and evaluation setup, not proof that structured memory is always unnecessary.
The mechanism matters: summaries and fact stores can discard relations or dependency paths needed by a later question. Before adding a learned writer or graph, compare with raw-history retrieval under the same reader, corpus cutoff, evidence budget, and grader. Measure evidence coverage, utilization, answer accuracy, ingestion/storage cost, retrieval latency, and update/delete correctness separately. Preserving raw evidence is conditional on consent and retention policy; it is not permission to keep everything forever.
A retrieval baseline can be strong while still needing access control, temporal validity, provenance, and deletion lineage. Route bounded write/read judgments through Section 16.7’s decision contract, then validate their downstream effect rather than rewarding compression alone.
WikiTrace: keep the evidence behind a lesson
As of 2026-11-15 — emerging research. WikiTrace links reusable lessons to run summaries and unchanged trajectories. An agent can inspect those sources when guidance is insufficient or conflicts with observations. A link preserves provenance; it does not prove the lesson correct. The evaluated system initially supplies all lessons, leaving large-memory retrieval unresolved, and its reasoning-based diagnostic labels are not causal explanations. [8]
The engineering implication is to store applicability, outcome and source identity beside each memory. Measure regressions as well as recovered successes; retain access controls and deletion lineage through summaries and source runs.
Quizzes
Quiz 1: Why is storing all past conversation text in a vector database usually insufficient for agent memory?
Because real memory systems need to distinguish between temporary context, specific past events, stable facts, and reusable rules. Treating everything as one type of text chunk makes retrieval noisy and update logic weak.
Quiz 2: Why is staleness one of the hardest memory problems?
Because the system must update what it currently believes without losing the historical record that earlier information once existed. It is an update problem, not just a storage problem.
Quiz 3: Why should memory entries track their source?
Because information from a user, another agent, or the model’s own inference should not carry the same trust level. Provenance helps prevent guesses from being treated like facts.
Quiz 4: Why does successful memory design quickly become a privacy question?
Because once a system can store and retrieve long-term user information effectively, it also needs retention limits, deletion rules, access boundaries, and clear storage ownership.
Quiz 5: Why can a correct answer hide a memory-write bug?
The reader may recover the answer from the prompt or another source while the persistent bank remains wrong. Inspect the bank after each event and test retrieval and generation separately.
References
-
Park, J. S., et al. (2023). Generative Agents: Interactive Simulacra of Human Behavior. arXiv:2304.03442.
-
Packer, C., et al. (2023). MemGPT: Towards LLMs as Operating Systems. arXiv:2310.08560.
-
Gutiérrez, B. J., Shu, Y., Gu, Y., Yasunaga, M., & Su, Y. (2025). HippoRAG: Neurobiologically Inspired Long-Term Memory for Large Language Models. arXiv:2405.14831.
-
Zhong, W., et al. (2023). MemoryBank: Enhancing Large Language Models with Long-Term Memory. arXiv:2305.10250.
-
Fei, T., et al. (2026). Hy-Memory-30B-A3B: Attributed Reinforcement Learning for Long-Term Memory Writing. Preprint. Source.
-
Toma, S.-A., et al. (2026). Beyond Downstream QA: Rethinking How We Evaluate Agent Memory. Preprint. Source.
-
Bao, Z., et al. (2026-10-22). Is Complex Agentic Memory Always Needed? Naive RAG Is Stronger Than We Thought. Preprint. arXiv:2610.30755v1.
-
Research preprint (2026). Don’t Just Trust Your Memory: Evidence-Linked Memory Reduces Memory-Induced Degradation in LLM Agents. Version pinned; accessed 2026-11-15.