arXiv:2610.22897cs.AIOct 2026

Manuscript Offprint

arXiv:2610.22897

When to Forget: Risk-Controlled Context Adaptation for Long-Horizon Agents

Chenle Chen, Yangbo Wei, Zhijie Zheng, Zhenyu Su, Qifan Wang, Junhong Qian, Chao Yao, Chen Wu, Lei He

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

ABSTRACT

Long-horizon agents learn from failure, but the value of a failure record can change as execution progresses. We study when retaining, compressing, or removing the same history block improves subsequent execution relative to full-history KEEP. We introduce RECAP, a framework that combines matched context interventions, execution-relational prediction, and independent policy certification. Matched environment states and rollout seeds measure success and continuation prompt-cost differences; prefix-only relations between a failure block and the current execution propose promising edits. Independent task bundles then select a policy subject to harmful-intervention and non-positive-benefit risk constraints under a fixed measurement protocol. A five-seed longitudinal case holds both the failure block and its summary fixed: compression fails at an early state and becomes a cost-saving intervention at a later state. Across five backbones, RECAP produces positive paired-success saving estimates with backbone-specific reliability-efficiency tradeoffs. On Hunyuan-A13B, it edits 43.24% of retained checkpoints while matching KEEP's observed 91.89% continuation success and reducing unconditional mean continuation prompt cost by 4,619.8 tokens (2.13%). The framework provides an execution-level reference for deciding when to forget: retain history by its value to what comes next.

1 INTRODUCTION

How long should a failure remain in an agent's memory? For tool-using language-model agents, rejected candidates prevent repeated search, failed checks reveal unmet constraints, and recovery traces preserve clues needed to complete a task (Yao et al., 2023; Shinn et al., 2023). These records are useful precisely because later decisions depend on them. However, as the environment changes, dependencies are resolved, or subgoals are completed, the same records may cease to affect the remaining execution while still consuming prompt tokens at every model call.

The difficulty is that the value of a history record depends on what the current execution still needs it for. An old failure can encode an active constraint; a semantically relevant record can become redundant after a state change. Recency and similarity describe properties of the record, but neither directly answers the intervention question: what would happen to subsequent success and cost if this record were compressed or removed now? Prompt compression and memory management offer mechanisms for reducing context (Jiang et al., 2023; 2024; Packer et al., 2023). Execution-aware selection additionally requires a reference against which the consequences of those edits can be measured.

Figure 1 makes this distinction concrete. We evaluate the same six failed slot checks and the same summary at two checkpoints of one course-selection trajectory. At step 15, KEEP succeeds while COMPRESS and DROP fail in all five seeds. At step 27, KEEP and COMPRESS recover in two steps, but COMPRESS saves 1,908 continuation prompt tokens; DROP takes 12 recovery steps. Recovery denotes the first valid check of the target slot, rather than task termination. The history block and its summary have not changed; their measured value to the remaining execution has.

(a) Growing agent history

Figure

(b) Age / similarity heuristics

(c) RECAP: execution-aware context adaptation

Matched state + seeds within each checkpoint

Figure

Figure 1: State-dependent value of the same failure block. (a–b) Schematic history growth and heuristic deletion. (c) One fixed block B and summary B′B' in a Qwen3-8B course-selection task, with five seeds and states matched across treatments within each checkpoint. At step 15, KEEP succeeds and COMPRESS fails; at step 27, both recover in two steps and COMPRESS saves 1,908 prompt tokens. Figure 3 compares all three treatments at seven checkpoints.

We formulate the decision as selective counterfactual improvement over KEEP. A finite-seed empirical oracle chooses a lower-cost edit only when recorded success does not decrease, retaining the original otherwise. RECAP (Risk-controlled Execution-aware Context Adaptation Policy) approximates edit value using prefix-only information about relevance, resolution, state changes, dependencies, and subgoals. It separates two roles: learned scores propose candidate editing policies; tests on independent calibration tasks select a policy whose two task-level risks meet prespecified budgets. KEEP is the fallback when the evidence does not support intervention. This separation instantiates Learn-Then-Test (Angelopoulos et al., 2021) for context adaptation rather than treating predictive scores themselves as safety certificates.

Our contributions are:

• An execution-based formulation of when to forget. Matched KEEP/COMPRESS/DROP continuations measure the success and cost effects of changing one identified failure block at a fixed checkpoint.

• Execution-relational proposal with independent risk control. Prefix-only relations construct candidate policies, and independent task-bundle tests select a rule under harmful-intervention and non-positive-benefit constraints.

• State-dependent evidence and cross-backbone tradeoffs. A fixed-block longitudinal case isolates changing intervention value, while a five-backbone, seven-selector comparison characterizes the resulting reliability, savings, and intervention coverage.

The study evaluates one intervention per matched continuation. This gives a controlled basis for learning and assessing an editing rule, with a certificate for the declared task-bundle protocol.