History as Retrieval Context
Table of Contents
1. The question
A context window is finite; a long-horizon task is not. Everything the agent did before this turn — observations, tool results, reflections, dead ends — either fits in the window or it does not. Once it does not, the agent's own past has to become a corpus: something addressable, searchable, injectable a slice at a time. This note is about the two ways a past becomes a corpus. The first is to retrieve it. The second, less discussed and more interesting, is to author it — to write the history so that retrieval runs over a designed artifact rather than a raw log.
The distinction matters because retrieval quality is bounded by what the history is. Index a transcript of everything and you retrieve a transcript of everything. The field has spent three years getting very good at the first move and quietly discovering it needs the second.
2. Retrieving the past
2.1. The memory stream: recency, importance, relevance
The canonical formulation is the memory stream of Generative Agents (Park et al. 2023). Every observation is stored as natural-language text; at retrieval, each memory is scored by a weighted sum of three terms — recency (exponential decay), importance (an LLM-rated salience), and relevance (embedding similarity to the current query) — and the top nodes are pulled into the planning context. Periodic reflection synthesizes higher-level memories from the raw stream. Every later system is, in part, a variation on which of those three terms it trusts and how it structures what gets scored.
2.2. The unit of retrieval: observation, trajectory, procedure
What you retrieve is a design choice, and it climbs a ladder of abstraction.
- The observation. The memory stream retrieves atomic events. Simple, and it scales badly: a thousand turns is a thousand nodes to score.
- The trajectory. Synapse (Zheng et al. 2024) stores whole state-abstracted trajectories and retrieves the most similar past run as an exemplar (99.2% on MiniWoB++). Reflexion (Shinn et al. 2023) keeps verbal reflections on past failures in an episodic buffer and re-injects them on the next attempt — reinforcement learning whose gradient is a sentence, not a weight. ExpeL (Zhao, Huang, et al. 2024) generalizes this across tasks: gather trajectories, distill cross-task insights, retrieve the top-k successful ones at inference.
- The procedure. The highest rung distills history into reusable routines. Voyager (Wang, Xie, et al. 2023) grows a skill library of executable code keyed by description embedding. Agent Workflow Memory (Wang et al. 2024) induces named workflows from trajectories and injects the relevant ones, offline or online. AutoGuide (Fu et al. 2024) compresses experience into state-conditioned guidelines retrieved by when they apply, not by surface similarity — a real advance, because it indexes history by applicability. Agentic Context Engineering (Zhang et al. 2025) pushes furthest: an evolving playbook curated by a Generator–Reflector–Curator loop, explicitly guarding against "context collapse" and "brevity bias."
The ladder is the story. Raw episodes are cheap to write and expensive to retrieve well; distilled procedures are expensive to write and cheap to apply. Moving up the ladder is moving from retrieval toward authoring.
2.3. The systems view: paging and operations over memory
MemGPT (Packer et al. 2023) reframes all of this as an operating system: a fixed "main context" (RAM) and an external searchable store (disk), with the agent issuing function calls to page its own history in and out. The history stops being a passive log and becomes an addressable store the agent queries. The production systems make the write path explicit: Mem0 (Chhikara et al. 2025) runs an extract-then-update pipeline (ADD / UPDATE / DELETE / NOOP over a persistent store); A-MEM (Xu et al. 2025) builds a Zettelkasten where each new memory autogenerates keywords and links to prior notes, so retrieval traverses an agent-constructed network; Zep (Rasmussen et al. 2025) maintains a bi-temporal knowledge graph that answers "what was believed at time T," the temporal dimension flat stores lack. ReasoningBank (Ouyang et al. 2025) distills generalizable strategies from the agent's own successful and failed trajectories and writes new ones back — self-evolution through retrieved strategy, up to +34% relative effectiveness.
Note what A-MEM, ACE, and ReasoningBank have in common: the memory is not the raw trace. It is a structure the agent wrote. That is the seam this note pulls on.
2.4. Retrieve, or hold it all?
If the window were infinite, none of this would be needed — so the honest prior question is whether to retrieve over history at all or just keep it in context. The evidence is that long-context models, when resourced, beat retrieval on average answer quality (Li et al. 2024), but retrieval is far cheaper and often matches a context-extended model at a fraction of the compute (Xu et al. 2023). The practical answer is route: Self-Route (Li et al. 2024) lets the model decide per query, and Self-RAG (Asai et al. 2024) trains the model to emit reflection tokens deciding when to retrieve and to critique what it gets back. Between the two extremes sit the compression methods — recursive summarization of dialogue into a running memory (Wang, Fu, et al. 2023), and at the mechanism level, KV-cache eviction that keeps only the "heavy hitter" tokens attention actually uses (Zhang et al. 2023). Compaction is the industry name for the same move (compaction against beads); it is summarization under deadline.
2.5. How we know it works
Two benchmarks anchor evaluation. LoCoMo (Maharana et al. 2024) scores very-long-term multi-session dialogue (hundreds of turns, temporal event graphs). LongMemEval (Wu et al. 2024) decomposes the problem into indexing –> retrieval –> reading and reports the number that motivates the whole field: commercial assistants lose roughly 30% accuracy over sustained interaction. History-as-retrieval is not a solved problem; it is a measured one.
2.6. The map
For the taxonomy, the anchor is Zhang et al.'s memory-mechanism survey (Zhang et al. 2024) (now ACM TOIS): memory by source, form, and operation; short- versus long-term; parametric versus retrieval-based. The self-evolving agents survey (Fang and others 2025) covers the loop that consumes retrieved history. This note's own decomposition of the products — MemGPT/Letta, Zep, Mem0, A-MEM — lives in the sibling Agent Memory Architectures.
4. Git history as context
Everything above treats conversational history. The richest instance of the same question is code, where the past is not a fuzzy transcript but a literal, typed, append-only log: the commit history. The two poles reappear exactly — mine the history, or author it — and the code setting has one thing the memory literature lacks: a control condition.
4.1. The genealogy the memory literature forgot
Co-change was solved in 2004. Zimmermann et al. (Zimmermann et al. 2004) mined association rules over CVS commit transactions — "programmers who changed this also changed that" — and surfaced them live in the ROSE tool; Ying et al. (Ying et al. 2004) reached the same result independently (IEEE TSE, recall/precision on Eclipse and Mozilla). Every modern "git history as context" feature is a rediscovery of this. What changed in 2026 is not the mining. It is the consumer of the mined result: in 2004 the co-change set drove a ranked file list read by a human; now it is retrieval context injected into a model. The honest caveat is that this is a genealogy of the signal, not a citation lineage — the 2004 work solved the mining, the 2026 work solves feeding it to a reader that can read prose.
4.2. Retrieval: mine the log
HAFixAgent (Shi et al. 2025) is the clearest case. It walks git
blame from the buggy line and injects slices — function names across co-changed
files, the before/after of the containing function, the blame commit's diff.
History adds +4.4% on Defects4J but +38.6% on BugsInPy, and the tail is the real
claim: 40–56% on complex multi-hunk bugs where the no-history baseline collapses
to 0%. The 9x asymmetry between the two datasets is a puzzle worth stating —
more consistent with history compensating for weak fault localization than with
provenance carrying independent signal. At production scale the same move appears
in the Unblocked context engine (Unblocked 2026), notable for
being the only surveyed system that ships time decay and counts review activity
as expertise.
4.3. Authored protocol: write the shadow
The write-side names what retrieval cannot recover. Lore
(Stetsenko 2026) proposes git trailers as the carrier for the decision
shadow — the constraints, rejected alternatives, confidence, and reversibility
that never survive into the diff — queryable with stock git log, no parser.
It is the cleanest instance of history-as-authored-protocol in the wild, and it
has the exact limit the pole implies: it only works forward from adoption. It
cannot read the decade already in the repo, which is precisely what the retrieval
pole is for. The two need each other. Adjacent: Git Context Controller
(Wu et al. 2025) and Letta's Context Repositories (Letta 2026)
apply git semantics to the agent's own memory (commit/branch/merge as memory
operations), and git-insight-mcp (HasanJahidul 2026) serves the
derived queries (who_touched, introducing_pr, co_change) over MCP — the
value is in the derived query, not the git access.
4.4. Does the capability even exist? The benchmarks
Three instruments, three answers. LoCoDiff (AbanteAI (Mentat) 2025) poses the purest version — given a file's diff sequence, emit its current state — and finds models near-perfect under 5k tokens but below 50% by 25k: holding history as long context degrades fast. SWE-Milestone (Deng et al. 2026) rebuilds executable milestone DAGs directly from commit logs and reports the diagnostic failure: frontier models drop from >80% on isolated tasks to <=38% on continuous evolution (~13% milestone resolve), with recall scaling linearly while precision saturates. Agents add the feature and break the neighbours — which is exactly what provenance context is supposed to prevent. GitGoodBench (Lindenbauer, Bogomolov, and Zharov 2025) bounds the scope from the other side: manipulating git (merge, rebase) is a separate capability from reading its history, with a separate failure curve (21% solve, 0% on hard merges), and conflating them is a common error in this literature.
4.5. The control: destroy the history
The strongest evidence that history carries recoverable signal comes from work
that was not trying to make the argument. ProgramBench (Yang et al. 2026)
asks models to rebuild programs (FFmpeg, SQLite, PHP) from a binary plus docs —
and to prevent leakage, wipes the .git/ directory and reinitializes with a
single anonymous commit. Zero tasks are fully resolved across nine models.
Commit0 (Zhao, Jiang, et al. 2024) is the earlier from-scratch framing (history
absent by construction rather than erased). History had to be destroyed for the
task to be hard: the clearest available evidence that a commit log is a usable
input, delivered by authors who treated it only as a contamination risk.
4.6. The rival framing
One honest counterpoint. "LLM Agents Can See Code Repositories" (Ma et al. 2026) compresses repository structure into a visual graph for -26% input tokens at equal accuracy — the competing answer to the same budget question. If the bottleneck is context economy rather than missing intent, structure compression beats history mining, and this whole section is answering a question that the structural axis sidesteps. The note's wager is that intent — the decision shadow, the co-change coupling — is the part structure cannot recover; the wager is not free.
5. Synthesis: one spectrum, one shared oracle problem
The two poles are ends of a single spectrum, not rivals. At one end, the raw memory stream: cheap to write, lossy to retrieve. At the other, a hand-authored spec or RFC: expensive to write, exact to retrieve. Everything in between — Reflexion's reflections, AWM's workflows, ReasoningBank's strategies, ACE's playbook — is a bet on how much authoring to do at write time versus how much inference to leave for retrieval time. The recent, most effective systems sit closer to the authoring end than the 2023 work did. That is the trend.
Both poles inherit one problem. Retrieval assumes the retrieved past is true; authoring assumes the author was right. Neither escapes the oracle question — was the history correct? — it only relocates it. A retrieved failed trajectory teaches the wrong lesson exactly as well as a right one; an authored protocol encodes a mistake with the full authority of structure. History as retrieval context is only as good as the history, however it was made. The verification disciplines that guard authored artifacts elsewhere on this site are the same ones a memory needs before an agent conditions on it.
An open question, and the governance seam: who authors. When the human authors the protocol, staleness is the risk. When the agent authors it, collapse is. The production systems are quietly choosing — Mem0's UPDATE/DELETE policy, ACE's Curator, A-MEM's link evolution are all answers to "who is allowed to rewrite the memory, and when." That is the next thing worth measuring.
6. Related
- Agent Memory Architectures: JITIR Against the Field — the product-and-contract decomposition (MemGPT, Zep, Mem0, A-MEM); this note is the technique-and-literature cut.
- Compaction Against Beads — compaction as summarization-under-deadline, the authoring-under-duress case.
- Visibility is Verification and Annotation Systems — verdict drawers as authored, retrievable memory of a decision.