arXiv(opens in a new tab)cs.CLAug 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2608.28476

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 Sun

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

Zhuoshi Pan1,2^{1,2}♣, Qizhi Pei3^{3}♣, Junru Lu2^{2}, Honglin Lin3^{3}, H. Vicky Zhao1^{1}♡, Di Yin2^{2}, Xing Sun2^{2}♡

1^{1}Tsinghua University 2^{2}Tencent Youtu Lab 3^{3}Shanghai AI Lab

Long-horizon agentic tasks require large language models (LLMs) to iteratively retrieve, integrate, and maintain dispersed information across multi-turn interactions, but preserving all interaction histories leads to a continuously growing working context. Recent proactive context management methods allow models to edit their own working context with specialized tools, yet they still face three key limitations: (1) a limited toolset restricted to search, deletion, and summarization, with no support for global planning, long-term memory, and adaptive compression; (2) inefficient exploration that treats context management actions uniformly despite their heterogeneous impacts on final outcomes; and (3) coarse-grained credit assignment that assigns the final trajectory-level reward to all intermediate context editing actions during RL. To bridge these gaps, we introduce ContextPilot, a proactive context management framework for long-horizon agentic reasoning. Our approach systematically augments the toolset with planning, long-term memory, and soft context offloading tools. We further propose an RL method tailored for context management, which uses context and entropy variation to identify critical editing decisions for branch sampling and estimates action-level advantages from all branched trajectories that pass through the corresponding context editing action. Experiments on long-context QA and deep search tasks show that ContextPilot achieves stronger performance with a more compact working context, consistently outperforming existing baselines across various base models and benchmarks.

Project: https://tencent.github.io/ContextPilot

Code: https://github.com/Tencent/ContextPilot

Model: https://huggingface.co/collections/panzs19/contextpilot

Correspondence: ♣ Equal Contribution; ♥ Corresponding Authors.

1 Introduction

Large language models (LLMs) have shown strong reasoning capabilities on information-intensive tasks, including long-context QA [1, 2] and deep search [3, 4]. These tasks require models to identify key evidence from long contexts, integrate complex relations, and, when necessary, seek information through multi-turn tool interactions [5]. Prevailing agentic paradigms like ReAct [6] typically append prior reasoning, tool calls and tool responses to the context as the interaction proceeds, resulting in a rapidly growing context. Prior studies [7–10] address context growth through human-designed workflows, where truncation or summarization is triggered by fixed rules. Although straightforward, they give the model no control over its own context, and are difficult to adapt to different scenarios [11]. To alleviate this, recent works [11–13] propose proactive context management, allowing models to spontaneously manage their working context through context editing tools. Despite its flexibility, this paradigm still faces three key limitations.

First, existing context management toolsets, which typically consist of search, deletion, and summarization, are insufficient for managing the context of long-horizon tasks. Effective context management requires more than simply removing or summarizing content: models also need to build long-term memory across scattered fragments [14,15][14, 15], maintain structured entity-event episodes [16][16], and plan globally before taking subsequent actions [6,17][6, 17]. Second, although recent studies [11,18][11, 18] have applied RL fine-tuning to help models further familiarize with context editing tools, their training procedures are not specifically adapted for context

ContextPilot

(a) Context Management Tool Design

Figure

(b) Context-Aware Partial Rollout

(c) Fine-Grained Credit Assignment

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.

management. Unlike common tools, context editing tools can substantially overwrite the interaction history and exert a larger influence on subsequent steps [7]. As shown in Figure 2, trajectory branches originating from different context management operations exhibit substantially different variance in their final success rates, indicating that certain operations are more sensitive than others. Unfortunately, traditional RL relies on trajectory-level rollouts [19], limiting adaptive exploration for various context management decisions. Third, existing training procedures directly assign the final trajectory-level reward to all intermediate context management actions, neglecting fine-grained credit assignment [20].

To address these challenges, we propose ContextPilot, a proactive context management framework for long-horizon agentic reasoning. Our contributions are threefold: (1) On the tool side, our framework extends the existing context management toolset with planning, long-term memory, and soft context offloading tools, enabling the agent to better control its context across long-horizon interactions. (2) On the training side, we design an RL training method tailored to context management. We propose context-aware partial rollout, which uses context and entropy variation to identify critical context management actions for branch sampling. For credit assignment, we incorporate rewards from all subsequent branches to estimate the advantage of an intermediate context management action, yielding a more fine-grained reward signal. (3) On the evaluation side, whereas prior work mostly focuses on long-context QA, we extend the evaluation to deep search tasks. Experiments on both tasks show that ContextPilot maintains a more compact context while achieving superior performance, bringing consistent gains and surpassing existing baselines.

References (42)