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.

3. History as an authored protocol

Every system above treats history as found data: a trace to be indexed, scored, retrieved. But retrieval fidelity is capped by the corpus. If the past is an undifferentiated log, the best retriever in the world hands you undifferentiated log. The move the strongest systems keep making — A-MEM's linked notes, ACE's curated playbook, AutoGuide's state-conditioned rules, ReasoningBank's distilled strategies — is to stop retrieving the raw past and start retrieving something authored from it. The claim of this section is that authoring is not a retrieval optimization; it is a different discipline, and worth naming as one.

History as an authored protocol: the past is deliberately written as a structured, provenance-annotated, versioned artifact, so that retrieval runs over a designed corpus with contracts rather than over a log with hopes. The distinction is the same one the literature draws between an episodic store (what happened) and a procedural one (what to do) — but pushed to its conclusion: if the procedural memory is what actually helps, author it directly and skip the induction.

This is not hypothetical; it is what disciplined agent practice already does, and each instance is a retrieval corpus by another name:

  • The transcript as narrative. A literate "STEP 1 … STEP N" session where each step states why the next expression runs is not a log — it is authored history whose structure is the index. Reading top-to-bottom is retrieval.
  • Verdict drawers and provenance. An annotation that records what was verified, by whom, with what finding (visibility is verification, annotation systems) is authored memory of a decision, retrievable by stable id. The agent does not re-derive the verdict; it retrieves the authored one.
  • Tickets and RFCs. A beads ticket, or a numbered RFC, is a unit of work-memory written to be found later. The history of the project is the authored protocol of its decisions, not the git reflog.
  • The operating protocol itself. An AGENTS.md / CLAUDE.md is history authored in advance — a protocol retrieved into context every session, encoding what the log would otherwise have to teach by example.

The trade is explicit. Authoring front-loads cost: you pay, at write time, to impose structure the retriever would otherwise have to recover. In return you bound retrieval error (you retrieve a contract, not a guess), you get auditability (provenance travels with the memory), and you get composition (protocols compose; logs concatenate). The risks are equally explicit: authoring cost, staleness (an authored protocol lies the moment the world moves and no one updates it), and — when the agent is the author — ACE's context collapse (Zhang et al. 2025), the self-authored memory degrading under its own edits.

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

7. References

AbanteAI (Mentat). 2025. “Locodiff-Bench: Long-Context Benchmark for Git History Comprehension.” https://github.com/AbanteAI/LoCoDiff-bench.
Asai, Akari, Zeqiu Wu, Yizhong Wang, Avirup Sil, and Hannaneh Hajishirzi. 2024. “Self-Rag: Learning to Retrieve, Generate, and Critique through Self-Reflection.” Arxiv Preprint Arxiv:2310.11511.
Chhikara, Prateek, Dev Khant, Saket Aryan, Taranjeet Singh, and Deshraj Yadav. 2025. “Mem0: Building Production-Ready Ai Agents with Scalable Long-Term Memory.” Arxiv Preprint Arxiv:2504.19413.
Deng, Gangda, Zhaoling Chen, Zhongming Yu, Haoyang Fan, Yuhong Liu, Yuxin Yang, Dhruv Parikh, et al. 2026. “Swe-Milestone: Evaluating Ai Agents on Continuous Software Evolution.” Arxiv Preprint Arxiv:2603.13428.
Fang, Jinyuan, and others. 2025. “A Comprehensive Survey of Self-Evolving Ai Agents: A New Paradigm Bridging Foundation Models and Lifelong Agentic Systems.” Arxiv Preprint Arxiv:2508.07407.
Fu, Yao, Dong-Ki Kim, Jaekyeom Kim, Sungryull Sohn, Lajanugen Logeswaran, Kyunghoon Bae, and Honglak Lee. 2024. “Autoguide: Automated Generation and Selection of Context-Aware Guidelines for Large Language Model Agents.” Arxiv Preprint Arxiv:2403.08978.
HasanJahidul. 2026. “Git-Insight-Mcp: Semantic Git Queries via Mcp.” https://github.com/HasanJahidul/git-insight-mcp.
Letta. 2026. “Introducing Context Repositories: Git-Based Memory for Coding Agents.” https://www.letta.com/blog/context-repositories/.
Li, Zhuowan, Cheng Li, Mingyang Zhang, Qiaozhu Mei, and Michael Bendersky. 2024. “Retrieval Augmented Generation or Long-Context Llms? a Comprehensive Study and Hybrid Approach.” Arxiv Preprint Arxiv:2407.16833.
Lindenbauer, Tobias, Egor Bogomolov, and Yaroslav Zharov. 2025. “Gitgoodbench: A Novel Benchmark for Evaluating Agentic Performance on Git.” In Proceedings of the 1st Workshop for Research on Agent Language Models (Realm 2025), 272–88. Association for Computational Linguistics.
Ma, Dongjian, Silin Chen, Yufei Yang, Yuling Shi, Yanfu Yan, and Xiaodong Gu. 2026. “Llm Agents Can See Code Repositories.” Arxiv Preprint Arxiv:2606.14061.
Maharana, Adyasha, Dong-Ho Lee, Sergey Tulyakov, Mohit Bansal, Francesco Barbieri, and Yuwei Fang. 2024. “Evaluating Very Long-Term Conversational Memory of Llm Agents.” Arxiv Preprint Arxiv:2402.17753.
Ouyang, Siru, Jun Yan, I-Hung Hsu, Yanfei Chen, Ke Jiang, Zifeng Wang, and others. 2025. “Reasoningbank: Scaling Agent Self-Evolving with Reasoning Memory.” Arxiv Preprint Arxiv:2509.25140.
Packer, Charles, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica, and Joseph E. Gonzalez. 2023. “Memgpt: Towards Llms as Operating Systems.” Arxiv Preprint Arxiv:2310.08560.
Park, Joon Sung, Joseph C. O’Brien, Carrie J. Cai, Meredith Ringel Morris, Percy Liang, and Michael S. Bernstein. 2023. “Generative Agents: Interactive Simulacra of Human Behavior.” Arxiv Preprint Arxiv:2304.03442.
Rasmussen, Preston, Pavlo Paliychuk, Travis Beauvais, Jack Ryan, and Daniel Chalef. 2025. “Zep: A Temporal Knowledge Graph Architecture for Agent Memory.” Arxiv Preprint Arxiv:2501.13956.
Shi, Yu, Hao Li, Bram Adams, and Ahmed E. Hassan. 2025. “Hafixagent: History-Aware Automated Program Repair Agent.” Arxiv Preprint Arxiv:2511.01047.
Shinn, Noah, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, and Shunyu Yao. 2023. “Reflexion: Language Agents with Verbal Reinforcement Learning.” Arxiv Preprint Arxiv:2303.11366.
Stetsenko, Ivan. 2026. “Lore: Repurposing Git Commit Messages as a Structured Knowledge Protocol for Ai Coding Agents.” Arxiv Preprint Arxiv:2603.15566.
Unblocked. 2026. “Inside the Unblocked Context Engine: How Relevance Is Decided.” https://getunblocked.com/blog/inside-the-unblocked-context-engine/.
Wang, Guanzhi, Yuqi Xie, Yunfan Jiang, Ajay Mandlekar, Chaowei Xiao, Yuke Zhu, Linxi Fan, and Anima Anandkumar. 2023. “Voyager: An Open-Ended Embodied Agent with Large Language Models.” Arxiv Preprint Arxiv:2305.16291.
Wang, Qingyue, Yanhe Fu, Yanan Cao, Shuai Wang, Zhiliang Tian, and Liang Ding. 2023. “Recursively Summarizing Enables Long-Term Dialogue Memory in Large Language Models.” Arxiv Preprint Arxiv:2308.15022.
Wang, Zhiruo, Jiayuan Mao, Daniel Fried, and Graham Neubig. 2024. “Agent Workflow Memory.” Arxiv Preprint Arxiv:2409.07429.
Wu, Di, Hongwei Wang, Wenhao Yu, Yuwei Zhang, Kai-Wei Chang, and Dong Yu. 2024. “Longmemeval: Benchmarking Chat Assistants on Long-Term Interactive Memory.” Arxiv Preprint Arxiv:2410.10813.
Wu, Junde, Minhao Hu, Jiayuan Zhu, Jiazhen Pan, Yuyuan Liu, Min Xu, and Yueming Jin. 2025. “Git Context Controller: Manage the Context of Llm-Based Agents like Git.” Arxiv Preprint Arxiv:2508.00031.
Xu, Peng, Wei Ping, Xianchao Wu, Lawrence McAfee, Chen Zhu, Zihan Liu, Sandeep Subramanian, Evelina Bakhturina, Mohammad Shoeybi, and Bryan Catanzaro. 2023. “Retrieval Meets Long Context Large Language Models.” Arxiv Preprint Arxiv:2310.03025.
Xu, Wujiang, Zujie Liang, Kai Mei, Hang Gao, Juntao Tan, and Yongfeng Zhang. 2025. “A-Mem: Agentic Memory for Llm Agents.” Arxiv Preprint Arxiv:2502.12110.
Yang, John, Kilian Lieret, Jeffrey Ma, Parth Thakkar, Dmitrii Pedchenko, Sten Sootla, Emily McMilin, et al. 2026. “Programbench: Can Language Models Rebuild Programs from Scratch?” Arxiv Preprint Arxiv:2605.03546.
Ying, Annie T. T., Gail C. Murphy, Raymond Ng, and Mark C. Chu-Carroll. 2004. “Predicting Source Code Changes by Mining Change History.” Ieee Transactions on Software Engineering 30 (9): 574–86. https://doi.org/10.1109/TSE.2004.52.
Zhang, Qizheng, Changran Hu, Shubhangi Upasani, Boyuan Ma, Fenglu Hong, Vamsidhar Kamanuru, and others. 2025. “Agentic Context Engineering: Evolving Contexts for Self-Improving Language Models.” Arxiv Preprint Arxiv:2510.04618.
Zhang, Zeyu, Xiaohe Bo, Chen Ma, Rui Li, Xu Chen, Quanyu Dai, Jieming Zhu, Zhenhua Dong, and Ji-Rong Wen. 2024. “A Survey on the Memory Mechanism of Large Language Model Based Agents.” Arxiv Preprint Arxiv:2404.13501.
Zhang, Zhenyu, Ying Sheng, Tianyi Zhou, Tianlong Chen, Lianmin Zheng, Ruisi Cai, Zhao Song, et al. 2023. “H2o: Heavy-Hitter Oracle for Efficient Generative Inference of Large Language Models.” Arxiv Preprint Arxiv:2306.14048.
Zhao, Andrew, Daniel Huang, Quentin Xu, Matthieu Lin, Yong-Jin Liu, and Gao Huang. 2024. “Expel: Llm Agents Are Experiential Learners.” Arxiv Preprint Arxiv:2308.10144.
Zhao, Wenting, Nan Jiang, Celine Lee, Justin T. Chiu, Claire Cardie, Matthias Gallé, and Alexander M. Rush. 2024. “Commit0: Library Generation from Scratch.” Arxiv Preprint Arxiv:2412.01769.
Zheng, Longtao, Rundong Wang, Xinrun Wang, and Bo An. 2024. “Synapse: Trajectory-as-Exemplar Prompting with Memory for Computer Control.” Arxiv Preprint Arxiv:2306.07863.
Zimmermann, Thomas, Peter Weißgerber, Stephan Diehl, and Andreas Zeller. 2004. “Mining Version Histories to Guide Software Changes.” In Proceedings of the 26th International Conference on Software Engineering (Icse), 563–72. https://doi.org/10.1109/ICSE.2004.1317478.