HyperAIHyperAI

Command Palette

Search for a command to run...

長期的タスクのためのエージェント的文脈管理(ACM)

Xiaochuan Li Ryan Ming Meng Chu Shuai Shao Rong Jin Chenyan Xiong

概要

エージェント的タスクは本質的に長期的かつ多ターンであり、環境との相互作用を通じて文脈を絶えず蓄積する。既存の文脈圧縮手法は不可避的に情報損失を招き、固定的なヒューリスティックルールによって起動されるため、エージェントの変化する推論の焦点と整合しない。我々は、エージェントに無損失の文脈管理のための専用の文脈編集ツールを装備させるフレームワークであるエージェント的文脈管理(ACM)を提案する。人間の短期記憶と長期記憶の相互作用に着想を得て、エージェントは自律的に文脈を圧縮するタイミングを決定し、破棄された内容を外部記憶システムに退避させ、後の検索のために必要に応じてそれを照会する。このフレームワークに基づき、我々はさらに、文脈管理の高品質な実演を構築し、エージェント的検索およびコーディングタスクの両方でモデル性能を向上させるポストトレーニングパイプラインを開発する。さらなる分析により、効果的な文脈管理がピーク時のトークン負荷を軽減し、拡張された探索を可能にし、独立した試行間でより一貫した解をもたらすことが明らかになる。

One-sentence Summary

Researchers from Carnegie Mellon University and Meta propose Agentic Context Management (ACM), a framework that equips agents with lossless context editing tools for autonomous, memory-inspired compression and retrieval, and demonstrate through a post-training pipeline that ACM reduces peak token pressure, extends exploration, and improves consistency on agentic search and coding tasks.

Key Contributions

  • Agentic Context Management (ACM) is introduced as a framework that gives language model agents explicit tools for lossless compression and retrieval of context, replacing external modules or fixed heuristics with agent-initiated decisions.
  • A teacher-guided post-training pipeline with dual constraints produces high-quality demonstrations of context management, enabling the model to learn when to compress and when to refrain without heavy reinforcement learning.
  • Experiments on agentic search and coding benchmarks show that ACM outperforms ReAct and summary-based baselines, with further analysis revealing reduced peak token pressure, longer exploration horizons, and more consistent solutions across independent trials.

Introduction

Large language model (LLM) agents tackling complex, long-horizon tasks generate verbose histories that mix reasoning traces with noisy tool outputs. These histories routinely exceed practical context limits, degrading performance even on models with nominally large context windows. Prior mitigation strategies include long-context pretraining (which still suffers degradation), hybrid attention (still bounded by the window), and heuristic context compression pipelines that rely on fixed, external rules rather than the model’s own reasoning.

The authors propose Agentic Context Management (ACM), a framework that gives the agent explicit memory tools so it can autonomously decide when to summarize and offload irrelevant information to external storage and when to retrieve it. They further introduce a teacher-student post-training pipeline with dual constraints that teaches the model when to invoke and when to avoid context management actions. This approach reduces peak token usage, extends test-time exploration, and yields more consistent solutions across independent trials.

Dataset

The authors construct a training dataset through a teacher-guided pipeline designed to teach models when to invoke context management tools. The data is generated dynamically from student model rollouts and teacher annotations rather than collected from static sources.

Dataset composition and sources

  • The dataset is built from student model trajectories on tasks that require context management.
  • A teacher model from the same model family annotates these trajectories under two complementary constraints.
  • The final training set mixes teacher-annotated data with resampled original student rollouts for stability.

Key details for each subset

  • Injection data (H⁻ rollouts): The student completes tasks without access to context management tools. The teacher, using a guided prompt, identifies turns where compression would be beneficial (e.g., redundant queries, unproductive loops, sufficient accumulated context) and inserts a context management action with a reasoning trace.
  • Refinement data (H⁺ rollouts): The student completes tasks with access to context management tools. The teacher identifies turns where the student’s compression calls are premature or unnecessary and replaces them with a more productive action (e.g., searching for evidence, opening a document, committing to an answer), again with a reasoning trace.
  • Resampled rollouts: Original student trajectories are resampled in a self-distillation manner and mixed in to stabilize training.

How the paper uses the data

  • The student is trained via on-policy distillation: the teacher provides soft next-token distributions (top-K, with K=20) for all assistant-token positions in the rollout.
  • The loss is applied only to assistant-generated tokens; system-prompt, user-input, and tool-output tokens are masked out.
  • This objective jointly teaches the student when to invoke context management and when to refrain.

Processing details

  • Quality filtering: Rejection sampling retains only trajectories where the student fails to complete all trials successfully, focusing learning on genuinely challenging problems. Content filters verify that the teacher’s reasoning traces do not leak information from the reference answer; annotations must cite trajectory-level cues (redundant queries, cyclic patterns, sufficient evidence) without revealing the target answer.
  • Cropping strategy: Not applicable; data comes from full model rollouts.
  • Metadata construction: Each annotated turn includes a replacement action and a reasoning trace that justifies the decision.

Method

The authors formulate the agent interaction where the agent πθ\pi_{\theta}πθ conditions on the accumulated history Ht={s,(a1,o1),,(at1,ot1)}H_t = \{s, (a_1, o_1), \dots, (a_{t-1}, o_{t-1})\}Ht={s,(a1,o1),,(at1,ot1)} to produce an action atπθ(Ht)a_t \sim \pi_{\theta}(\cdot \mid H_t)atπθ(Ht), and the environment returns a response otπγ(Ht;at)o_t \sim \pi_{\gamma}(\cdot \mid H_t; a_t)otπγ(Ht;at). The interaction terminates when the agent selects a finish action or the context window limit is reached. Unlike the ReAct paradigm, which eventually hits the context limit, or the Summary Agent paradigm, where an external monitor forces compression when usage exceeds a predefined threshold and discards original messages, the proposed Agentic Context Management (ACM) framework allows the agent to autonomously manage its context.

Drawing inspiration from human cognition, the ACM agent utilizes two context management tools to mimic short-term and long-term memory mechanisms. The manage_context tool compresses previous turns into a concise summary and offloads the raw messages to an external file on disk, while the query_memory tool allows the agent to query the stored raw messages to retrieve information precisely. When the agent invokes manage_context, a summarizer LLM compresses all messages up to the previous summary boundary. Crucially, the original messages are preserved in external storage and mapped to the summary via a unique identifier. When the agent needs to revisit earlier content, it invokes query_memory with the specified identifier, and a querier LLM returns the relevant information. This design ensures lossless information compression and agent-initiated context management, allowing the agent to invoke compression at any point during the reasoning process rather than relying on a fixed schedule.

To address the challenge of determining the appropriate timing for context management, the authors design a teacher-guided data generation pipeline with dual constraints. The pipeline employs a teacher-student framework operating in two phases.

In the first phase, Student Rollout, a student model completes the task under two conditions: with and without access to context management tools, producing trajectories denoted H+H^+H+ and HH^-H, respectively. H+H^+H+ captures the student's untrained usage behavior of the tools, while HH^-H reflects its ordinary exploration behavior. In the second phase, Teacher Annotation, a teacher model receives guided instruction prompts P+P^+P+ or PP^-P along with the corresponding student trajectory and the reference answer AA^*A. The teacher produces annotations under two complementary constraints. For injection on HH^-H, the teacher using P+P^+P+ identifies turns where context management would be beneficial, such as when the student begins querying redundant topics or enters unproductive loops, and replaces the action with a context management tool call ata_t'at. For refinement on H+H^+H+, the teacher using PP^-P identifies turns where the student's context management calls are premature or unnecessary, replacing the inappropriate call with a more productive action ata_t'at, such as searching for additional evidence.

The student is then trained using on-policy distillation. A stronger teacher from the same model family annotates each student-generated assistant token with a soft next-token distribution. The student is optimized to match these teacher distributions over all assistant-token positions in the rollout using the following loss function:

LACM(θ)=Eτπθ[tTa(τ)vVpT(vs;h<t)logπθ(vs;h<t)].\mathcal{L}_{\mathrm{ACM}}(\theta) = - \mathbb{E}_{\tau \sim \pi_{\theta}} \Bigg[ \sum_{t \in \mathcal{T}_a(\tau)} \sum_{v \in \mathcal{V}} p_{\mathrm{T}}(v \mid s; h_{<t}) \log \pi_{\theta}(v \mid s; h_{<t}) \Bigg].LACM(θ)=Eτπθ[tTa(τ)vVpT(vs;h<t)logπθ(vs;h<t)].

where τ\tauτ is a trajectory sampled from the student policy, Ta(τ)\mathcal{T}_a(\tau)Ta(τ) denotes the set of assistant-token positions, and V\mathcal{V}V contains the teacher's top-K candidate tokens at position ttt. The distribution pT(s;h<t)p_{\mathrm{T}}(\cdot \mid s; h_{<t})pT(s;h<t) denotes the teacher probabilities restricted and renormalized over V\mathcal{V}V, while πθ(s;h<t)\pi_{\theta}(\cdot \mid s; h_{<t})πθ(s;h<t) denotes the student's next-token distribution. The loss is applied to all student-generated assistant tokens, while system-prompt, user-input, and tool-output tokens are masked out.

To ensure data quality, the authors apply two filtering mechanisms. Rejection sampling retains only trajectories in which the student fails to complete all trials successfully, ensuring the student learns from the teacher's behavior on genuinely challenging problems. Content filters verify that the teacher's reasoning traces do not leak information from the reference answer AA^*A, encouraging the model to recognize compression-worthy patterns from the trajectory structure rather than memorizing answer-dependent cues. Finally, to stabilize training, trajectories are resampled from the student's original rollouts and mixed with the teacher-annotated data.

Experiment

The evaluation uses three long-horizon benchmarks (BrowseComp-Plus, DeepSearchQA, SWE-Bench Verified) with Qwen3.5-9B as the student model and a much larger teacher for on-policy distillation. The ACM framework enables agents to proactively compress context, which already outperforms ReAct, summary-based, and memory-based baselines; post-training on curated context management data yields a 27% relative gain and nearly matches models 40 times larger. Behavior analysis shows ACM agents trigger compression well before context limits, dramatically reducing peak token usage while enabling more exploratory tool calls, and the approach narrows the gap between Pass@1 and Pass@4 by making correct solutions more reliable. Ablations confirm that dedicated context management data and teacher distillation are complementary, and a case study demonstrates the model self-monitoring, re-reading compressed history, and maintaining a compact working window through a 222K-token trajectory.

ACM uniquely combines active compression, trainable policy, lossless storage, agent-initiated triggers, and open-source training data, unlike prior methods which each omit one or more of these properties. Post-training on context-management data substantially improves reliability (Pass@1 and Pass^4) and narrows the gap to Pass@4, while also increasing the frequency of compression and retrieval tool calls. Combining synthesized context-management data with general distillation yields the best overall performance, as the two sources provide complementary skills. ACM is the only method that is simultaneously compact, trainable, lossless, agent-initiated, and trained on open-source data. Prior memory-augmented approaches accumulate knowledge across tasks but do not compress working context within a single episode. Post-training on context-management data substantially raises Pass@1 and Pass^4, making correct solutions more reliable rather than only expanding the capability boundary. GPT-5.5 distillation alone fails to surpass the post-trained ACM agent on agentic search, while dedicated context-management data delivers consistent gains across tasks. Combining distillation with context-management data yields the best overall performance, indicating the two sources are mutually reinforcing. ACM post-training increases the frequency of manage_context and retrieval tool calls, enabling broader exploration of reasoning paths. In a case study, the model self-monitors and compresses only under genuine memory pressure, interleaving compression with memory probes while keeping the working window well below the limit.

Equipping an agent with the ACM framework improves performance over baselines, and post-training on context management data yields further gains including a 27% relative improvement on BrowseComp-Plus. The approach enables smaller models to explore more effectively through increased tool calls while simultaneously reducing peak token usage, lowering both reasoning burden and KV-cache overhead. ACM-equipped agents surpass all baselines without post-training, demonstrating the effectiveness of agent-initiated context management. Post-training on context management data yields a 27% relative gain on BrowseComp-Plus and approaches the performance of open-source models 40 times larger. Smaller agent models rely more on exploration via tool calls to solve problems, and context management enables them to explore effectively. Peak token usage decreases dramatically under the ACM framework, especially compared to the Summary Agent, reducing model reasoning burden and server KV-cache overhead. Post-training on context management data substantially increases Pass@1 and consistency across trials by keeping context clean and well-organized.

Combining distilled trajectories from a strong teacher with synthesized agentic context management data yields the best overall performance across tasks, though the two sources contribute complementary strengths. Context management data alone consistently improves performance and increases tool usage for exploration, while distillation alone can underperform the base agent on search tasks. The results indicate that dedicated context management training is necessary and that distillation and ACM data are mutually reinforcing. Adding ACM data alone improves pass@1 over the base model on all three tasks, whereas distillation alone reduces pass@1 on BrowseComp-Plus and DeepSearchQA. ACM training substantially increases the average number of tool calls per episode on search tasks, with the +ACM variant issuing 46.2 tools on BrowseComp-Plus compared to 30.8 for the base model. Distillation alone reduces peak token count on DeepSearchQA but raises it on BrowseComp-Plus, while ACM alone lowers peak tokens on both search benchmarks relative to the base model. Combining distillation with ACM achieves the highest pass@1 on BrowseComp-Plus and SWE-Bench Verified, but slightly underperforms ACM alone on DeepSearchQA.

The evaluation compares an Active Context Management (ACM) agent against baselines on agentic search and software engineering tasks. ACM uniquely integrates active compression, a trainable policy, lossless storage, agent-initiated triggers, and open-source training data. Post-training on synthesized context-management data significantly improves reliability and consistency, while combining this data with general distillation from a strong teacher yields the best overall performance, as the two sources provide complementary skills. The ACM framework enables smaller models to explore more effectively through increased tool calls while simultaneously reducing peak token usage and KV-cache overhead.


AIでAIを構築

アイデアからローンチまで — 無料のAIコーディング支援、すぐに使える環境、最高のGPU価格でAI開発を加速。

AI コーディング補助
すぐに使える GPU
最適な料金体系

HyperAI Newsletters

最新情報を購読する
北京時間 毎週月曜日の午前9時 に、その週の最新情報をメールでお届けします
メール配信サービスは MailChimp によって提供されています