CoACT: 33% Token Reduction for Coding Agents via Action-Preserving Compression
Tsinghua researchers propose CoACT, an observation compression method for coding agents that preserves the agent's next action, cutting token consumption by 33% on SWE-bench Verified while maintaining pass rates, using a two-stage training approach and a Next-Action Preservation criterion.
Coding agents solving software tasks repeatedly view code, modify programs, and run tests. Each step's returned file contents, search results, and logs remain in context and must be re-sent in the next call. As tasks grow harder, context lengthens, increasing per-step token processing and cost. Statistics show that on SWE-bench Verified, these observations account for 45.7% of total token consumption, reaching 67.8% on Terminal-Bench.
Limitations of Existing Compression Methods
Existing approaches fall into two categories. One rewrites history: sliding windows discard earlier commands and outputs, while AgentDiet lets the model periodically review history and delete redundant or unused content. However, rewriting history prevents full reuse of the original KV cache, forcing the model to re-prefill the rewritten content — token count may drop but overhead does not necessarily decrease.
The other category compresses new observations before they enter context, leaving prior history untouched and preserving cache reuse. CoACT follows this KV-cache-friendly path.
Core Idea: Next-Action Preservation (NAP)
The agent's execution loop can be viewed as “read output, execute action, receive new output.” Assuming identical initial environment and deterministic environment responses, if each compression step preserves the agent's next action, the subsequent action sequence and final result theoretically remain unchanged.
CoACT formalizes this as Next-Action Preservation (NAP): given the same task goal and history, compare the agent's next action after reading the original observation versus the compressed observation. For example, if the agent originally decides to view a called function after reading a code snippet, and still does so after compression, the compression preserves the next action. This allows per-compression validation without waiting for task completion.
Training Data Construction via NAP
A lightweight compressor (based on Qwen3.5-4B) is trained in several steps:
A teacher model (Gemini3-Flash) generates 8 compression candidates for each observation.
The agent samples 8 reference actions under the original observation.
Each candidate's induced action is compared against the reference actions; the top-3 most similar actions are averaged. Similarity is measured by parsing command operation type, target file, and read range — syntactically different commands that read the same code region are considered identical.
Candidates scoring ≥0.6 pass; the shorter passing version is selected as a training demonstration. If all 8 fail, the original observation becomes the target, teaching the model when to retain content.
Two-Stage Training: Offline Guidance and Online Alignment
Using only uncompressed agent trajectories for data collection introduces a distribution shift: during data collection the agent sees full history, but at deployment earlier steps are also compressed, altering the history.
CoACT addresses this with two stages:
Stage 1: Supervised fine-tuning on offline trajectories yields an initial compressor.
Stage 2: The compressor participates in actual agent runs, retaining previously compressed history, re-evaluating action preservation and length filtering to produce a second dataset.
Final compressor is trained on the merged dataset.
Ablation shows the offline-only compressor achieves 56.0% PASS@1 (vs. 57.0% uncompressed), while adding online data raises it to 60.5% with comparable token reduction.
Experimental Results: One-Third Token Savings, No Performance Loss
On 200 randomly sampled SWE-bench Verified instances, CoACT reduces token consumption across three models:
Qwen3.5-35B-A3B: 3.795M → 2.428M tokens
Deepseek-v4-Pro: 1.068M → 0.868M tokens
Gemini3-Flash: 0.685M → 0.422M tokens
Average reduction: 33.0%
Average PASS@1 improves from 69.0% to 71.0%: Qwen +3.5 points, Gemini +4.0 points, Deepseek -1.5 points. Average interaction steps drop from 56.5 to 51.2.
Post-compression, long observations (>1K tokens) on Qwen fall from 32.3% to 9.4% of all observations.
Comparison with Baselines
On Qwen, LLMLingua-2 reduces PASS@1 from 57.0% to 50.0% while increasing total tokens from 3.795M to 10.329M; SWE-Pruner increases to 4.471M; LongCodeZip reduces to 3.165M; CoACT achieves 2.428M with 60.5% PASS@1. On Deepseek, all three baselines exceed the uncompressed 1.068M tokens, while CoACT lowers to 0.868M — the lowest total tokens on both models. This demonstrates that merely shortening observation length does not guarantee lower overall task cost.
Compatibility with History Compression (AgentDiet)
CoACT can be combined with history rewriting methods. Alone, AgentDiet reduces total tokens but raises estimated cost from $41.26 to $45.65 due to KV cache disruption. Adding CoACT before AgentDiet lowers estimated cost to $25.88 (≈43.3% reduction) while maintaining similar success rates.
Paper and Code
Paper: CoACT: Action-Preserving Observation Compression for Coding Agents (ICSE 2027, Top 5%).
ArXiv: https://arxiv.org/abs/2607.02911
Code: https://github.com/THU-Agent/CoACT
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
