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

ContextPilot: Teaching Agents for Proactive Context Management via Fine-grained RL

Zhuoshi Pan, Qizhi Pei, Junru Lu, Honglin Lin, H. Vicky Zhao, Di Yin, Xing SunarXiv 2026

TL;DR

ContextPilot is a novel framework that empowers Large Language Model (LLM) agents to proactively manage their own working context during long-horizon tasks. By expanding the agent's toolset with memory and compression capabilities and introducing a tailored reinforcement learning (RL) method with fine-grained credit assignment, ContextPilot achieves state-of-the-art performance on QA and deep search tasks while maintaining a significantly more compact context window.

What Problem Does This Paper Address?

When LLM agents tackle long-horizon tasks—such as deep web research or multi-turn document QA—they generate a massive trail of interaction histories, tool calls, and observations. Standard agentic paradigms (like ReAct) simply append everything to the prompt, leading to rapid context bloat, high inference costs, and the notorious "lost in the middle" retrieval degradation.

While recent "proactive context management" methods allow models to call tools to edit, delete, or summarize their own context, they suffer from three major limitations:

  1. Restricted Toolsets: They are typically limited to basic search, deletion, and summarization, lacking support for global planning or structured long-term memory.
  2. Inefficient Exploration: Standard RL training treats all context management actions uniformly, ignoring the fact that some editing decisions have a much higher impact on the final outcome than others.
  3. Coarse Credit Assignment: Traditional RL assigns the final success or failure reward to all intermediate actions equally, which can mistakenly penalize a great context-cleaning action just because the agent later failed a factual retrieval step.

Methods

ContextPilot addresses these gaps through a system-level overhaul of both the agent's toolset and its RL training pipeline.

Figure 1. Overview of ContextPilot: (a) Extending the context management tools to support planning, long-term memory, and soft context offloading; (b) Improved RL training algorithm with context-aware partial rollout and (c) fine-grained snapshot-level credit assignment.

1. An Augmented Toolset

The authors expand the agent's capabilities beyond simple deletion and summarization by introducing:

  • Planning: A plan tool to propose concise strategies before executing actions.
  • Long-Term Memory: Tools like memorize and readMemory to extract structured entity-event episodes and store them externally.
  • Soft Context Offloading: Advanced compression tools like compressContext (powered by LLMLingua-2) and foldHistory to clear out bulky raw text while preserving core semantic information.

2. Context-Aware Partial Rollout

To optimize exploration during RL, ContextPilot calculates an Impact Score for context management actions based on two metrics: context variation (how much the context length changed) and entropy variation (how much the model's token uncertainty changed). Actions with high impact scores are selected as branching points where the training algorithm samples multiple sub-trajectories, focusing the compute budget on critical decisions.

3. Fine-Grained Credit Assignment

Instead of relying on sparse, trajectory-level rewards, ContextPilot introduces snapshot-level rewards. For any intermediate context-editing action, its reward is calculated by averaging the final outcomes of all subsequent branched trajectories that passed through it. This isolates the quality of context management from unrelated downstream mistakes. The policy is optimized using Group Relative Policy Optimization (GRPO).

Datasets

  • Supervised Fine-Tuning (SFT): Trajectories were synthesized using Qwen3.5-397B on the PublicDomain split of NovelQA and the training split of NarrativeQA.
  • Reinforcement Learning (RL) Training: Performed on LongBench-v2 (for long-context QA) and a 1K sample from OpenSeeker (for deep search).
  • Evaluation Benchmarks:
  • Long-Context QA: NovelQA, $\infty$Bench, LongMemEval-S, and BrowseComp+.
  • Deep Search: GAIA (text-only subset), BrowseComp, BrowseComp-ZH, and xBench-DeepSearch.

Key Insights and Ideas

  • The Correctness vs. Quality Mismatch: A key motivation for this work is that final task correctness does not always align with context management quality. An agent might find the right answer through messy, repetitive, and inefficient retrieval, while another might manage its context beautifully but miss a final fact. Snapshot-level credit assignment is essential to decouple these behaviors.
  • Heterogeneous Tool Sensitivity: The authors discovered that different tools cause wildly different variances in final success rates. Tools like readChunk and deleteContext are highly sensitive turning points in a trajectory, justifying the need for adaptive exploration budgets.
  • RL Reshapes Strategy: As RL training progresses, the agent naturally shifts away from naive, heavy information retrieval toward a balanced use of planning, memory management, and soft context offloading.

Key Results

  • Outperforming Larger Context Windows: Operating within a strict 32K context window, ContextPilot consistently outperformed baseline models utilizing a 128K context window.
  • State-of-the-Art QA: ContextPilot-8B-RL outperformed StateLM-8B-RL by an average of 3.55 points across the four long-context QA benchmarks.
  • Token Efficiency: While standard web agents show linear context growth that quickly maxes out the context window, ContextPilot successfully stabilizes its input token usage per turn to a flat 8K–10K tokens.
Figure 4. Token usage per turn on BrowseComp.
  • Deep Search Success: On complex deep search tasks, ContextPilot achieved an average performance boost of 1.51 points over SUPO across both WebSailor-7B and WebExplorer-8B backbones.

Limitations and Future Work

While highly effective, the authors note a few limitations:

  • Toolset Coverage: The current toolset still may not cover every niche context-editing demand, leaving room for richer hierarchical organization operations.
  • Hyperparameter Tuning: Due to heavy computational constraints, extensive hyperparameter sweeps for the partial rollout and credit assignment mechanisms were not conducted.
  • Scope of Evaluation: The framework was validated primarily on text-based QA and web search. The authors highlight extending proactive context management to broader environments—like agentic coding and GUI-based desktop agents—as an important future direction.

Summary updated

BibTeX
@misc{pan2026contextpilot,
  author = {Zhuoshi Pan and Qizhi Pei and Junru Lu and Honglin Lin and H. Vicky Zhao and Di Yin and Xing Sun},
  title = {{ContextPilot: Teaching Agents for Proactive Context Management via Fine-grained RL}},
  year = {2026},
  eprint = {2608.28476},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2608.28476},
}
Figure