arXiv:2610.27377cs.AIOct 2026

Manuscript Offprint

arXiv:2610.27377

REM: What to Store, When to Recall, What to Forget in Experience Memory for Coding Agents

Xinyi Lisa Chen, Pedro Herrero-Vidal, Xiaohan Chen, Xiaojing Yu, Cris Liu, Bingqing Song, Bin Xu, Suleiman A. Khan, You-Lin Chen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Large language model (LLM) agents now autonomously complete long-horizon tasks, such as repository-level coding, through hundreds of think-act steps, yet the experience each run produces is rarely reused on the next. Prior memory systems concentrate on retrieval, finding the most relevant past trajectory. Retrieval cannot observe the running agent, so it cannot decide whether the agent needs an experience, at which point, or for how long. We introduce REM (Reusable Experience Memory), a framework that manages the memory lifecycle from inside the agent's think-act loop through three explicit decisions. What to store: each completed trajectory is consolidated into a phase-structured document, two orders of magnitude smaller than the trajectory. When to recall: the document is injected at the start of the task; the costlier implementation record is withheld until an in-loop gate detects the agent struggling. What to forget: the record is evicted after a single exposure. On repository-level bug fixing (SWE-ContextBench Lite), REM retrieves the related trajectory more accurately than every state-of-the-art memory system (68.7% vs. 55.6% match@1) and improves, in every replicate, end-task resolution (27.6% vs. 24.9%) at 17% lower cost. Injecting the same experience as a summary or raw trajectory, even when oracle-retrieved, does not. Ablating any of the three decisions reduces resolution. Altogether, these results demonstrate that the bottleneck in experience reuse is not retrieval fidelity but how experience is stored and governed across its lifecycle, opening a control-theoretic perspective on agent memory.

1 Introduction

LLM agents now run unattended for hours, solving exploratory tasks such as repository-level coding [Jimenez et al., 2024] and text-to-SQL [Yu et al., 2018] through hundreds of think-act steps. Each run produces a detailed trace of exploration, dead ends, and an eventual solution, and a growing ecosystem of memory layers [Chhikara et al., 2025, Zhu et al., 2026] and experience-reuse frameworks [Shinn et al., 2023, Zhao et al., 2024, Wang et al., 2024, 2023] promises to make that experience compound. In practice it rarely does.

Most work targets the middle of the lifecycle: retrieving the most relevant past trajectory. Three findings from this literature suggest retrieval is not where reuse fails. First, agents use only a fraction

∗^{*}These authors contributed equally to this work.

†^{\dagger}Corresponding authors.

‡^{\ddagger}Work done while an intern at Amazon.

40th Conference on Neural Information Processing Systems (NeurIPS 2026). Workshop: Continual Learning for Enterprise AI Agents (CLEA).

of the context they receive, and retrieval alone is insufficient because they must actively interpret what they are given [Zhu et al., 2026]. Second, irrelevant or poorly placed context degrades performance, as models are distracted by irrelevant material and use long contexts unevenly by position [Shi et al., 2023, Liu et al., 2024]. Third, abstraction transfers better than detail: Hu et al. [2026] report negative transfer from detailed trajectories, concentrated on the hard cases where guidance is most needed.

These findings share a cause: retrieval cannot observe the state of the running agent, so what happens to a retrieved experience once it enters a long-running loop is left unmanaged. This is most consequential where an agent runs repeatedly against an evolving codebase, its accumulated experience a standing asset whose compounding is the long-run aim of continual learning for agents [Hu et al., 2026]. We take one step toward that aim, reusing a fixed pool of past runs within a single new run, and find the state of the receiving agent decisive: naively recalled memories leave resolution unchanged even when an oracle supplies the correct experience, and the same memory that helps mid-capability agents costs the strongest ones (§5.5), while agents reference only about a quarter of the identifiers in a raw trajectory and half of those in a prose summary (§5.3).

We introduce REM (Reusable Experience Memory), which manages the memory lifecycle from inside the agent's think-act loop, where the agent's state is observable (Figure 1), through three explicit decisions. What to store: each trajectory is consolidated into one phase-structured document organized by the four phases shared by diagnostic work, localize, understand, fix, and verify. It is two orders of magnitude smaller than the trajectory and serves as both the retrieval unit and the injected context, so stored tokens are spent once. When to recall: the document is injected at task start, while the trajectory's implementation record, far costlier and more distracting, is withheld until an in-loop node observes the agent struggling. What to forget: the record is evicted after a single exposure, while the document stays in context for the whole run. Every stage is a swappable policy slot, and the extraction schema, the only domain-specific artifact, is discovered automatically from example trajectories (§3.3).

We evaluate on SWE-ContextBench Lite [Zhu et al., 2026], judging memory by end-task resolution rather than retrieval accuracy alone. This work presents the following main contributions.

• From which to when. The value of a recalled experience depends on the state of the receiving agent, which makes agent memory a control problem, not a lookup problem.

• REM. A framework that governs the full memory lifecycle from inside the agent’s loop—phased consolidation, a two-tier read path, struggle-gated recall, and one-shot eviction—with an automatically discovered extraction schema, its only domain-specific artifact (§3).

• State-of-the-art retrieval; improved resolution at lower cost. The phased document is the most accurate retrieval unit on SWE-ContextBench Lite by a 13-point margin, and REM improves resolution in every replicate while cutting cost 17%, whereas start-of-run summaries and raw trajectories do not improve resolution, even with an oracle ( §5.2§5.2, §5.1§5.1).

• Decision-level ablations. Isolating each lifecycle decision shows the stored form drives the gains, while gating and eviction keep a costly second tier from doing harm, and a utilization analysis links the effect to how much injected context agents actually use ( §5.4§5.4, §5.3§5.3).

References (30)