ACM: Agentic Context Management – Enabling LLM Agents to Autonomously Manage Their Context for Long-Horizon Tasks
ACM: Agentic Context Management for Long Horizon Tasks
ACM (Agentic Context Management) is a framework that enables LLM agents to autonomously decide when to compress their context using two purpose-built tools (manage_context and query_memory), achieving lossless compression by offloading discarded content to external memory. A teacher-student post-training pipeline with dual constraints internalizes context management capabilities, yielding a 27% relative improvement on BrowseComp-Plus and an 8% improvement on SWE-Bench Verified over ReAct baselines on a 9B model.
TL;DR
Agentic tasks produce long, noisy trajectories that exceed context windows, even with million-token support. Prior compression methods are lossy and triggered by rigid heuristics. ACM introduces two memory tools (manage_context and query_memory) that allow the agent to autonomously decide when to compress and retrieve context losslessly. A dual-constraint teacher-student training pipeline internalizes this ability, achieving a 27% relative improvement on BrowseComp-Plus and an 8% improvement on SWE-Bench Verified over ReAct baselines on a 9B model.
Background Positioning: This work is a practical, post-training-focused contribution that bridges the gap between heuristic context compression (e.g., ReSum, ACON) and full RL-based memory management (e.g., Mem1, SUPO). It provides a scalable, open-source data generation pipeline and demonstrates that agent-initiated, lossless context management is both learnable and highly effective.
Problem & Motivation
Why is context management hard for agents?
Long-horizon agentic tasks—multi-step search, complex code editing—generate verbose histories: failed attempts, redundant observations, lengthy tool outputs. Even with a 128K context window, the signal-to-noise ratio degrades, and the model's reasoning quality suffers. The core challenge is when and how to compress without losing critical information.
Prior Work Limitations
- Heuristic compression (ReSum, ACON, DeepSeek-V3.2): compression is triggered by fixed token thresholds, external to the agent's reasoning. This leads to premature or unnecessary compression, and the compressed content is one-way—raw messages are discarded.
- Memory-augmented approaches (Mem1, ACE, AgentFold): maintain external memory, but either require full RL training from scratch, do not work within a single episode, or lack open-source data pipelines.
- Key gap: No existing method combines lossless compression (raw content preserved for later retrieval) with agent-initiated timing (the agent decides when to compress based on its own reasoning state).
Research Intuition
The authors draw inspiration from human cognition: we keep immediately relevant information in working memory and offload less immediate details to external storage, retrieving them on demand. By giving the agent two simple tools—manage_context (compress and save) and query_memory (retrieve)—the agent can autonomously mimic this behavior, expanding or contracting its effective context as needed.
Methodology
ACM Framework
ACM introduces two tools:
manage_context: Compresses all messages since the last compression boundary into a summary (8K tokens or less). The raw messages are preserved on disk, indexed by a uniquesummary_id. The summary is returned as a tool result, keeping the working context compact.query_memory: Takes asummary_idand a natural language query. The system retrieves the raw messages from that summary and uses an LLM to extract relevant information, returning it to the agent.
Crucially, compression is agent-initiated—the model itself decides when to call manage_context, based on its reasoning state. This is in contrast to the "Summary Agent" paradigm where an external monitor triggers compression at a fixed token threshold.

Training Pipeline: Dual-Constraint Teacher-Student
The authors found that even frontier models (e.g., GPT-5.5) rarely invoke context management autonomously. To internalize the skill, they design a post-training pipeline:
- Student Rollout: The student (Qwen3.5-9B) completes the task twice: once without context management tools (H⁻) and once with them (H⁺).
- Teacher Annotation: A stronger teacher (Qwen3.5-397B-A17B) reviews both trajectories against the reference answer:
- Injection on H⁻: The teacher identifies turns where context management would be beneficial (e.g., when the student is stuck in a loop) and injects a
manage_contextorquery_memoryaction. - Refinement on H⁺: The teacher identifies turns where the student called context management prematurely (e.g., when it should have searched further or committed to an answer) and replaces the call with a more productive action.
- Injection on H⁻: The teacher identifies turns where context management would be beneficial (e.g., when the student is stuck in a loop) and injects a
- Training: The student is fine-tuned via on-policy distillation against the teacher's soft next-token distributions, learning both when to invoke and when to refrain from context management.

Experiments & Results
Main Results
| Method | BrowseComp-Plus (Pass@1) | DeepSearchQA (Pass@1) | SWE-Bench Verified (Pass@1) |
|---|---|---|---|
| ReAct (Qwen3.5-9B) | 0.570 | 0.367 | 0.489 |
| ReSum (Qwen3.5-9B) | 0.608 | 0.371 | 0.475 |
| ACON (Qwen3.5-9B) | 0.614 | 0.380 | 0.480 |
| ACM Base (Qwen3.5-9B) | 0.635 | 0.405 | 0.508 |
| ACM Post-Trained (Qwen3.5-9B) | 0.727 | 0.425 | 0.530 |
| Gemini3-Flash (frontier) | 0.733 | 0.619 | 0.732 |
Table: Main results on three benchmarks. ACM-Post-Trained achieves a 27% relative gain on BrowseComp-Plus and nearly matches frontier models 40× larger, while using fewer peak tokens.
Key observations:
- 27% relative improvement on BrowseComp-Plus over ReAct.
- Peak token usage drops ~20% compared to summary-based baselines, reducing KV-cache overhead.
- Tool call frequency increases significantly, enabling deeper exploration.
Context Growth Dynamics

The sawtooth pattern in ACM trajectories shows that compression is triggered proactively, well before the context limit. This allows the agent to sustain much longer exploration (up to 222K raw tokens processed while keeping the working window under 128K).
Pass@K Consistency
ACM significantly improves Pass4 (all 4 trials correct), indicating that a clean context leads to more consistent solutions. The gap between Pass@1 and Pass4 narrows, suggesting that context management not only expands the set of solvable problems but also makes correct solutions more reliable.
Critical Analysis & Conclusion
Summary
ACM introduces a paradigm shift in context management: agent-initiated, lossless compression. The dual-constraint training pipeline is a practical, scalable method to internalize this ability, and the open-source release of data generation code enables broader adoption.
Strengths
- Lossless: Unlike summary-based methods, raw content is always retrievable, enabling precise information recovery.
- Agent-initiated: Timing aligns with the agent's reasoning state, not a fixed heuristic.
- Scalable training: The teacher-student pipeline can be applied to any existing model checkpoints without full RL.
- Proven gains: Significant improvements across search and coding tasks, with reduced peak token usage.
Limitations
- Requires strong base model: Context management is only meaningful when the agent can sustain long, coherent rollouts. 4B models collapse to 2-turn trajectories and never benefit from compression.
- Re-implemented baselines: Prior methods (ReSum, ACON, ACE) were re-implemented to match the evaluation setup; minor implementation differences may exist.
Future Work & Open Questions
- Can ACM be extended to multi-modal agents (e.g., vision-language navigation, robotic control) where context includes non-textual observations?
- How does ACM interact with long-context models that support 1M+ tokens? Is compression still beneficial beyond a certain window size?
- The dual-constraint pipeline could be generalized to other agentic skills beyond context management, such as task decomposition or tool selection.
Final Takeaway
ACM shows that the key to effective long-horizon agentic reasoning is not just larger context windows, but smarter, agent-driven context management. By giving the agent the ability to compress and retrieve losslessly, and by training it to use this ability appropriately, we can unlock significantly more effective exploration and more consistent solutions.
