NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning Agent-Compatible Context Management for Long-Horizon Tasks

Lu Yi, Runlin Lei, Liuyi Yao, Yuexiang Xie, Yuyang Li, Wenhao Zhang, Zhewei Wei, Yaliang Li, Jian-Yun NiearXiv 2026

TL;DR

Adaptive Context Management (AdaCoM) introduces an external, RL-trained LLM manager to dynamically prune, merge, and rewrite the context window of a frozen, closed-source LLM agent. This approach significantly boosts performance on long-horizon tasks and uncovers a fundamental "Fidelity-Reliability Trade-off" governing how different agents handle context.

What Problem Does This Paper Address?

Long-horizon tasks like deep research, multi-constraint web searches, or complex coding require LLM agents to execute dozens of sequential steps. As tool outputs, environment observations, and intermediate reasoning accumulate, agents suffer from long-context degradation. Stale or irrelevant information obscures critical evidence, amplifies positional biases, and causes the agent to forget original task constraints or fall into repetitive loops.

Existing context management solutions typically place the burden on the agent itself (e.g., prompting the agent to summarize its history or use pruning tools). However, this requires fine-tuning the agent to learn these self-management protocols—an approach that is completely impractical for popular, closed-source frontier models (like GPT-4o or Claude 3.5 Sonnet). Furthermore, rigid, one-size-fits-all strategies like periodic summarization ignore the fact that different agent architectures require different context styles.

Methods

The authors propose AdaCoM (Adaptive Context Management), a framework built on two core principles: architectural decoupling and operation-level flexibility.

Figure 1: Overview of Adaptive Context Management (AdaCoM). Before each agent step, an external LLM manages the context presented to the frozen agent. Task feedback updates only the manager, enabling Ada- CoM to discover agent-compatible context management strategies without training the underlying agent.
  • Architectural Decoupling: The primary task-solving agent remains completely frozen. Before each step, a smaller external LLM (initialized from Qwen3-4B-Instruct) acts as a "Memory Modifier" to optimize the context history.
  • Flexible Action Space: Instead of relying on fixed summarization, the manager outputs a structured JSON plan detailing specific modifications. It can delete useless tool outputs, rewrite verbose text, merge related steps, or even alter message roles (e.g., changing assistant text to user text to force the agent to pay closer attention to specific constraints).
  • Two-Stage Training: The manager is first warmed up via Supervised Fine-Tuning (SFT) on high-quality edit trajectories. It is then optimized using Group Relative Policy Optimization (GRPO), a reinforcement learning framework.
  • Hybrid Rewards: The RL loop optimizes the manager using a combination of outcome rewards (final task correctness judged by an LLM) and rule-based process rewards (penalties for exceeding context limits, making redundant tool calls, or generating invalid JSON).

Datasets

The framework was evaluated across two long-horizon, knowledge-intensive task families:

  1. BrowseComp-Plus: A web search benchmark with a verified corpus where agents use search and document retrieval tools to answer complex, multi-constraint questions.
  2. MCP-Bench-Wiki: A newly constructed, highly controlled benchmark based on Wikipedia Model Context Protocol (MCP) servers. It consists of 4,740 SFT samples, 1,000 RL training tasks, and a 150-task evaluation split designed to test multi-step tool coordination and long-form report synthesis.

Key Insights and Ideas

  • The Fidelity-Reliability Trade-off: The optimal context management strategy depends heavily on the underlying agent's strength. Stronger agents (with high vanilla performance) benefit from tiered management—preserving raw, high-fidelity trajectories and only compressing occasionally in large batches. Weaker agents perform better with eager distillation—frequent, aggressive compression that keeps the context short and forces the agent to stay within its reliable reasoning regime.
  • Capability-Based Transferability: Context managers are not narrowly tied to the specific agent they were trained on. They transfer remarkably well to unseen target agents if those agents share a similar baseline capability level.
  • Emergent State Tracking: Without explicit prompting, the manager naturally learns to maintain a compact "state note" at the top of the context window. This note dynamically tracks satisfied/unresolved constraints, current leads, and rejected candidates, preventing the agent from repeating failed actions.

Key Results

AdaCoM consistently outperformed vanilla ReAct loops and fixed-summarization baselines across diverse agent backbones (including Qwen3-Max, DeepSeek-V3, Kimi-K2-Instruct, and GLM-4.5-Air).

Figure 2: Per-agent trajectory outcome distri- bution shifts (%) on BrowseComp-Plus, com- puted as AdaCoM minus ReAct.
  • BrowseComp-Plus: AdaCoM achieved an average relative accuracy improvement of 39.0% across all agents, with a massive 95.0% relative gain for Kimi-K2-Instruct by successfully mitigating its tendency to fall into repetitive tool-use loops.
  • MCP-Bench-Wiki: AdaCoM delivered substantial improvements on deep research tasks, yielding a 22.3% relative gain for DeepSeek-V3 and a 9.0% gain for Kimi.
  • Cross-Agent Transfer: In cross-agent transfer experiments across 28 distinct pairs, 23 configurations achieved positive gains over vanilla ReAct, proving that a handful of representative context managers can be reused across a wide suite of models.

Limitations and Future Work

  • Inference Overhead: Introducing an external manager requires an additional LLM inference step before every single agent action, increasing token costs and wall-clock latency. The authors note that triggering the manager only periodically could mitigate this.
  • KV Cache Invalidation: Because the manager dynamically modifies historical messages, it frequently invalidates the agent's Key-Value (KV) cache, reducing serving efficiency. Developing cache-aware context managers is a critical next step.
  • Manager Capacity: A small 4B manager model can occasionally introduce lossy paraphrasing or omit fine-grained details that ultra-strong frontier models might have otherwise exploited. Future work will explore scaling up the manager's size.

Summary updated

BibTeX
@misc{yi2026learning,
  author = {Lu Yi and Runlin Lei and Liuyi Yao and Yuexiang Xie and Yuyang Li and Wenhao Zhang and Zhewei Wei and Yaliang Li and Jian-Yun Nie},
  title = {{Learning Agent-Compatible Context Management for Long-Horizon Tasks}},
  year = {2026},
  eprint = {2605.30785},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.30785},
}
Figure