Active Context Compression: Autonomous Memory Management in LLM Agents
Nikhil Verma
TL;DR
This work tackles the context window bottleneck in LLM agents by introducing Focus, an agent-centric mechanism for active intra-trajectory memory compression. Through the Focus Loop (start_focus, explore, complete_focus, withdraw) and a Knowledge block, the agent prunes raw history while preserving essential learnings, creating a sawtooth context pattern. In experiments on five SWE-bench Lite tasks with aggressive prompting, Focus achieves about 22.7% overall token savings without reducing task accuracy, and shows substantial savings on exploration-heavy tasks. The results demonstrate that deliberate prompting and an agent-controlled compression cadence can enable cost-efficient, autonomous memory management for long-horizon software engineering tasks, with opportunities for further refinement via fine-tuning or RL-based approaches.
Abstract
Large Language Model (LLM) agents struggle with long-horizon software engineering tasks due to "Context Bloat." As interaction history grows, computational costs explode, latency increases, and reasoning capabilities degrade due to distraction by irrelevant past errors. Existing solutions often rely on passive, external summarization mechanisms that the agent cannot control. This paper proposes Focus, an agent-centric architecture inspired by the biological exploration strategies of Physarum polycephalum (slime mold). The Focus Agent autonomously decides when to consolidate key learnings into a persistent "Knowledge" block and actively withdraws (prunes) the raw interaction history. Using an optimized scaffold matching industry best practices (persistent bash + string-replacement editor), we evaluated Focus on N=5 context-intensive instances from SWE-bench Lite using Claude Haiku 4.5. With aggressive prompting that encourages frequent compression, Focus achieves 22.7% token reduction (14.9M -> 11.5M tokens) while maintaining identical accuracy (3/5 = 60% for both agents). Focus performed 6.0 autonomous compressions per task on average, with token savings up to 57% on individual instances. We demonstrate that capable models can autonomously self-regulate their context when given appropriate tools and prompting, opening pathways for cost-aware agentic systems without sacrificing task performance.
