arXiv:2611.00244cs.CLOct 2026

Manuscript Offprint

arXiv:2611.00244

MEMENTO: Learning Context Management for Long Context Processing Agents

Yunfan Zhang, Taehoon Hwang, Kathleen McKeown, Smaranda Muresan

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

Abstract

LLM agents that operate over long inputs must perform context management: deciding what to retain in a fixed-size context window. A common approach is compaction, where the model replaces its history with a self-generated note. Yet off-the-shelf agentic models, including GPT-5.5 and GLM-5.3, often write ineffective notes, and reinforcement learning (RL) alone rarely discovers useful note-taking behavior. We present MEMENTO, a long-context agent built on Qwen3-8B and trained to manage its context through compaction. We first bootstrap note-taking by fine-tuning on synthetic trajectories annotated with notes generated in hindsight, then reinforce it with RL using a reward that combines answer correctness, note-quality heuristics, and confidence calibration. Although trained only to compact into a fresh window, MEMENTO extends at test time to strategies such as context folding and confidence-based backtracking. On book-level question answering across four benchmarks, with books of up to 2.5M tokens, MEMENTO raises Qwen3-8B's accuracy from 36.9% to 67.8% while never holding more than 20K tokens in context. It outperforms GPT-5.5 agent in the same harness (13.1%) and full book context (56.7%) at less than 1/50 the cost. It also nearly matches a ~100× larger GLM-5.3 agent (69.3%) at 1/9 the cost, and comes within 6.4 points of GLM-5.3 full context at 1/26 the cost.

1 Introduction

Large language model (LLM) agents are taking on ever longer tasks, and the horizon over which they can work autonomously has grown steadily (Kwa et al., 2025). This makes agents a natural fit for long-context processing: rather than ingesting an entire book or knowledge base at once, an agent can search the input and read only the parts it needs. Most agents, however, follow the ReAct paradigm (Yao et al., 2023b), appending every thought, action, and observation to their context.

Figure

Figure 1: Context management methods incorporated in this work. (a) Compaction starts a new window containing only the saved notes and discards all prior turns. (b) Context folding additionally retains the turns after the latest note. (c) Confidence-based backtracking resumes from an earlier note checkpoint after a low-confidence answer and generates an alternative continuation.

Because the history grows with the task while the context window stays fixed, a sufficiently long task will eventually exhaust the window. Larger context windows only postpone the problem: LLMs underuse information in long inputs (Liu et al., 2024), and their performance can degrade as the context grows (Du et al., 2025). Deciding what an agent should retain, which we call context management, is therefore central to agentic long-context processing.

Prior approaches either prompt the model to manage its own memory or delegate summarization to a separate component (Packer et al., 2023; Wu et al., 2025). Another line of work learns context management through reinforcement learning or supervised fine-tuning (Zhou et al., 2026; Yu et al.,

2026; Sun et al., 2026; Ye et al., 2026).

In this work, we jointly design the training pipeline and the test-time harness for context management in agentic long-context processing. We take book-level multi-hop question answering (Book QA) as our target task, since answering a single question often requires gathering evidence scattered across an entire book. Alongside standard search and view tools, the agent has a compaction note tool that it may call at any point to summarize its progress, record mistakes, and plan next steps. Notes persist through every context management operation we consider (Figure 1) and double as checkpoints for backtracking.

We present MEMENTO, a long-context processing agent built on Qwen3-8B (Qwen Team, 2025). Off-the-shelf LLMs, including stronger models such as GPT-5.5 and GLM-5.3, never make valid calls to our compaction note tool to record progress or plan ahead, even when explicitly introduced in their system prompt, leaving RL with little useful note-taking behavior to reinforce. We therefore shape the initial policy with synthetic SFT data. We inject compaction notes post hoc into correct GLM-5.3 (Z.ai, 2026) agent rollouts and fine-tune on the resulting synthetic trajectories. We further train the SFT-initialized policy with RL, using a reward that combines format compliance, heuristics on note quality, final-answer correctness, and, optionally, the calibration of a verbalized confidence score.

Throughout training, the agent uses only the simplest operation, compaction into a new window (Figure 1a), carrying its notes across multiple windows within a single rollout. Because context folding (b) and confidence-based backtracking (c) operate on the same notes and prompts, we can adopt them at test time with minimal train-test mismatch, and choose among these methods according to the accuracy and budget of a given deployment.

We train and evaluate MEMENTO on LiteraryQA (Bonomo et al., 2025), NovelHopQA (Gupta et al., 2025), and the English subset of SagaScale (Du et al., 2026), and additionally evaluate on NovelQA (Wang et al., 2025), which is held out from training. On 4.7K test questions, with accuracy micro-averaged over the four datasets, our full system reaches 67.8%. This greatly improves the 36.9% of the original Qwen3-8B agent and nearly matches the 69.3% of a ∼100×\sim100\times larger GLM-5.3 agent, with all agents run in the same harness using context folding and confidence-based backtracking. The conventional long-context approach, placing the entire book in GLM-5.3's context window, yields 74.3%, 6.4 points higher, but at more than 26×26\times the inference cost (in USD). MEMENTO also outperforms GPT-5.5, which reaches only 13.1% in our harness and 56.7% even with the full book in its context window, at 54×54\times our cost. These results suggest that a small open model agent can process long-context inputs effectively when context management is learned jointly with the task and the harness.

Our contributions are as follows:

• SFT and RL for learned context management. We bootstrap note-taking with SFT on agentic rollouts augmented with synthetic compaction notes, then refine it with RL under a hybrid reward that incorporates process signals on note quality with outcome rewards on answer correctness. Together, they improve the Qwen3-8B agent from 36.9% to 66.3%.

• Confidence-guided backtracking. We reward calibrated verbalized confidence during RL and use it at test time to backtrack over saved notes and retry low-confidence answers, raising accuracy further to 67.8%.

• Co-designed training and test-time harness. The agent can call the compaction note tool at any point in its trajectory, so the same note structure allows several test-time strategies: compaction into a new window, context folding, and backtracking to earlier notes. Although the agent is trained only with compaction into a new window, it transfers to folding and backtracking with minimal train–test mismatch, so the harness can be chosen to fit a deployment's cost–accuracy trade-off.