arXiv:2610.11287cs.CLOct 2026

Manuscript Offprint

arXiv:2610.11287

REMORY: Learning Residual Memory for Context Compaction

Hanchen Xia, Baoyou Chen, Yutang Ge, Naihao Deng, Senqiao Yang, Zilong Dong, Weihao Yuan, Siyu Zhu

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

Abstract

Long-horizon agents compact their history to continue within a finite context window, but a textual summary alone may not support every subsequent decision. We introduce REMORY, a neural memory network that supplements the summary with a bounded sequence of soft memory tokens. Given the history and summary, the network learns to generate tokens that help a frozen LLM approximate the continuation it would produce with the full history. The tokens are conditioned on the summary and appended after it, forming an analogue of a residual connection along the sequence dimension. On SummHay, REMORY improves source attribution at nearly unchanged insight coverage and approaches the full-context joint score using only 5.2% of the input positions. Across long-horizon agent benchmarks, Qwen3.8-27B and GLM-5.3-Flash show consistent gains with residual memory. Both models also exhibit substantially fewer repeated tool outputs and tool errors on BrowseComp and Terminal-Bench 2.1.

1 Introduction

Long-horizon agents work within a finite context window. As observations, tool outputs, and decisions accumulate, they must compact their history to continue. A common practice today is to replace earlier interaction with a textual summary. For example, popular coding agents such as Claude Code and Codex CLI provide /compact to free context space (Anthropic, 2026; OpenAI, 2026a). The summary becomes a checkpoint from which the agent resumes its work. Input length follows a sawtooth pattern: it grows with interaction, drops at compaction, and grows again (Figure 2a).

A textual checkpoint changes how prior context is available to the agent. Preserving the main thread does not guarantee that the summary will support every subsequent decision, and the relevance of earlier context can change as the task unfolds. We do not assume that the information needed beyond the summary can be identified or enumerated in advance. The challenge is to sustain useful access to prior context across compaction without keeping the entire interaction in the active window.

Human cognition illustrates how a limited active workspace can support sustained work. While contemporary agent contexts span roughly 0.2–1.0 million token positions, human working memory holds only a few chunks under controlled conditions (Baddeley, 2012; Cowan, 2001). Yet people can pursue complex projects over months or years, repeatedly drawing on details, experience, and learned skills in long-term memory (Ericsson & Kintsch, 1995; Squire & Dede, 2015). This ability depends on access to stored knowledge as well as active maintenance. Hippocampal indexing theory describes one form of neural indexing: partial cues activate an index that reinstates distributed cortical representations of an earlier experience (Teyler & Rudy, 2007).

Preprint

☐ Qwen w/o residual

☐ Qwen w/ residual

GLM w/o residual

GLM w/ residual

(a) BrowseComp

Figure

(b) Terminal-Bench 2.1

Figure 1: BrowseComp and Terminal-Bench 2.1 scores. Pale and solid bars compare the same local actor without and with residual memory. Gray bars are published frontier references, with their original harnesses and protocols (Google DeepMind, 2026; Terminal-Bench Team, 2026; OpenAI, 2026b); they are not controlled comparisons with our runs.

(a) Repeated compaction

Figure

(b) Human memory

Figure

Figure 2: Context compaction and human memory. (a) Input length across successive requests in an agent run, showing repeated growth and sharp reductions. (b) Memory systems illustrated using the Harvard–Oxford atlas (Harvard–Oxford Atlas Contributors, 2026): prefrontal regions (blue), hippocampus (cyan), and association cortex (purple).

Figure 2b illustrates the complementary memory systems involved (Goldman-Rakic, 1995; Kumaran et al., 2016). For agents, this suggests pairing an explicit checkpoint with a learned neural representation that keeps prior context useful as work continues.

We introduce REMORY, a neural memory network for context compaction. Given a history and its generated summary, we train the network to generate a bounded sequence of soft memory tokens that can be appended after the summary, helping a frozen LLM approximate the continuation it would produce with the full history. We call this residual memory because the soft tokens are both conditioned on the summary and appended after it, forming an analogue of a residual connection along the sequence dimension. The summary supplies a readable checkpoint, while the learned tokens supplement it during subsequent decisions. Exact records remain accessible through ordinary archive and file-retrieval tools.

On SummHay, residual tokens improve source attribution at nearly unchanged insight coverage. This supports an associative interpretation: the memory helps connect recovered claims to supporting evidence. Across long-horizon agent benchmarks, Qwen3.8-27B and GLM-5.3-Flash show consistent gains with residual memory. Residual memory also reduces repeated tool outputs and tool errors for both models on BrowseComp and Terminal-Bench 2.1. REMORY pushes the 320B-parameter GLM-5.3-Flash (Z.ai, 2026a) towards frontier-level performance (Figure 1).

Preprint

References (26)