Long-horizon agentic tasks require large language models (LLMs) to iteratively retrieve, integrate, and maintain dispersed information across multi-turn interactions. However, preserving all interaction histories leads to a continuously growing working context, which can degrade performance and increase computational costs.
Recent proactive context management methods allow models to edit their own working context with specialized tools, but they face three key limitations: a limited toolset restricted to search, deletion, and summarization; inefficient exploration that treats all context management actions uniformly; and coarse-grained credit assignment that assigns the final trajectory-level reward to all intermediate context editing actions during reinforcement learning.
To address these gaps, the researchers introduce ContextPilot, a proactive context management framework for long-horizon agentic reasoning. The approach systematically augments the toolset with planning, long-term memory, and soft context offloading tools. It also proposes a tailored RL method that 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. The code is available at https://github.com/Tencent/ContextPilot.