ACM: Agentic Context Management for Long Horizon Tasks

Xiaochuan Li, Ryan Ming, Meng Chu, Shuai Shao, Rong Jin, Chenyan XiongarXiv 2026

TL;DR

LLM agents tackling long-horizon tasks quickly overwhelm their context windows with verbose tool outputs and reasoning traces, leading to performance degradation. Agentic Context Management (ACM) solves this by giving agents explicit, human-like memory tools to autonomously and losslessly offload and retrieve context on demand. Combined with a novel dual-constraint post-training pipeline, ACM significantly improves agent performance, reduces peak token usage by 20%, and enables longer, more consistent problem-solving explorations.

What Problem Does This Paper Address?

When LLM agents interact with complex environments over long periods (e.g., multi-step web searches or repository-scale coding), their interaction histories grow massive. Even models with nominal context windows of millions of tokens suffer from "lost in the middle" phenomena and increased reasoning noise when flooded with verbose tool outputs and failed exploration loops.

Prior context compression methods rely on rigid, external heuristics—such as forcing a summarization step whenever the context window hits 90% capacity. These approaches are typically lossy (discarding the original raw text) and externally triggered, meaning they don't align with the agent's internal reasoning state. The authors address this by asking: Can we enable agents to manage their own context windows dynamically and losslessly?

Methods

The authors introduce the Agentic Context Management (ACM) framework, which mimics the interplay between human short-term (working) memory and long-term storage.

Agents are equipped with two purpose-built tools:

  1. manage_context: The agent autonomously decides to compress its recent history into a concise summary. Crucially, the raw, uncompressed messages are saved to an external disk space and mapped to a unique summary ID, keeping the active working context clean.
  2. query_memory: If the agent needs to revisit the granular details of an earlier phase, it invokes this tool with a specific summary ID and a natural language query to retrieve the exact raw text needed.
Figure 1: Overview of our ACM Framework. ReAct eventually hits the context limit, while the Summary Agent is forced to compress whenever usage exceeds a predefined threshold (e.g., 90% of the context in the figure) and discards the original messages. The ACM agent autonomously decides when to manage its context losslessly.

To teach the model when and how to use these tools, the authors developed a Teacher-Guided Post-Training Pipeline utilizing dual constraints:

  • Injection: The student model rolls out without memory tools. A stronger teacher LLM reviews the trajectory and injects manage_context calls at critical points where the student got stuck in loops or accumulated redundant context.
  • Refinement: The student rolls out with full access to memory tools. The teacher reviews this trajectory and removes premature or unnecessary context management actions, replacing them with more productive actions like deeper searches or final answers.

The student model is then optimized using on-policy distillation based on these teacher corrections.

Figure 2: Overview of the dual-constraint training data generation pipeline. A student agent completes task rollouts both with and without context management tools. A teacher model reviews each trajectory against the reference answer and either injects ACM action or replaces non-ACM actions.

Datasets

The framework was trained and evaluated across three long-horizon agentic benchmarks:

  • BrowseComp-Plus: A complex web-browsing and search benchmark (680 training examples, 150 evaluation).
  • DeepSearchQA: An out-of-domain evaluation benchmark testing the agent against a live web search engine across 17 domains.
  • SWE-Bench Verified: A software engineering benchmark evaluating the agent's ability to resolve real-world GitHub issues (trained using the SWE-Gym dataset).

Key Insights and Ideas

  • The "Sawtooth" Context Pattern: When agents manage their own context, their token usage exhibits a characteristic sawtooth pattern. They proactively compress information well before hitting hard context limits, driven entirely by their internal reasoning state.
  • Lossless is Key: Retaining the ability to query the raw text via query_memory prevents the catastrophic information loss common in standard summarization pipelines.
  • The Capability Threshold: Context management is an emergent requirement for capable models. The authors found that smaller "thinking" models (like Qwen3-4B-Thinking) suffer from rollout collapse—they give up and guess after just two turns, meaning they never enter the long-horizon regime where context management provides value.

Key Results

Integrating ACM into Qwen3.5-9B yielded substantial performance gains over standard ReAct and heuristic summary baselines:

  • Accuracy Boosts: Achieved a 27% relative gain on BrowseComp-Plus, a 16% gain on DeepSearchQA, and an 8% gain on SWE-Bench Verified.
  • Efficiency: Reduced peak token pressure by approximately 20%, lowering server KV-cache overhead.
  • Exploration Horizon: Active context management unlocked longer test-time exploration, allowing the post-trained model to issue significantly more search and document-fetching calls to find correct answers.
Figure 3: Input token count over interaction turns for ACM and ReAct agents. Gray curves show individual ACM trajectories; red dots mark context management calls. Yellow and blue curves denote the population average for ReAct and ACM, respectively.

Limitations and Future Work

The primary limitation of ACM is its dependency on a strong base model. If the underlying LLM lacks the fundamental reasoning capacity to sustain extended, multi-turn tool interactions, it will terminate early and never benefit from context management tools.

Additionally, because prior context-compression baselines had not been tested on the specific benchmarks chosen for this paper, the authors had to re-implement them manually, leaving open the possibility of minor implementation discrepancies. Future work could explore scaling this approach to even larger open-source models and optimizing the retrieval latency of the long-term memory store.

Summary updated

BibTeX
@misc{li2026acm,
  author = {Xiaochuan Li and Ryan Ming and Meng Chu and Shuai Shao and Rong Jin and Chenyan Xiong},
  title = {{ACM: Agentic Context Management for Long Horizon Tasks}},
  year = {2026},
  eprint = {2607.23809},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.23809},
}
Figure