Skip to content
CoACT: How Tsinghua Cut Coding Agent Token Costs by 33% Without Losing Performance

CoACT: How Tsinghua Cut Coding Agent Token Costs by 33% Without Losing Performance

Tsinghua researchers propose CoACT, an observation compression method for coding agents that preserves the agent's next action, reducing token consumption by 33% on SWE-bench Verified while maintaining task success rates across three LLM models.

Data Party THU
Data Party THU
Data Party THU

Problem: Observation Tokens Dominate Coding Agent Costs

When coding agents solve software issues, they repeatedly view code, modify programs, and run tests. Each step's returned file contents, search results, and logs remain in the context and must be resent in the next call. As tasks grow harder, context lengthens, increasing per-step token usage and cost. Statistics show that on SWE-bench Verified these observations account for 45.7% of total token consumption, and on Terminal-Bench up to 67.8%.

Limitations of Existing Compression Methods

Prior 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 breaks KV Cache reuse, forcing the model to re-prefill the rewritten content — token count drops but compute overhead may not. The second category compresses new observations before they enter the context, leaving prior history untouched and preserving KV Cache. CoACT follows this KV-Cache-friendly path.

CoACT: Action-Preserving Observation Compression

Core Idea: Next-Action Preservation (NAP)

The agent's execution loop is "read output, execute action, receive new output." Assuming identical initial environment and deterministic environment responses, if the agent's next action remains unchanged after reading a compressed observation, the subsequent action sequence and final result will theoretically stay the same. CoACT defines Next-Action Preservation (NAP): given the same task goal and history, compare the agent's next action when fed the original observation versus the compressed one. If the actions match (same operation type, target file, and read range), the compression preserves the next action. This allows per-compression validation without running the full task.

Training Data Construction via NAP

A lightweight compressor (based on Qwen3.5-4B) is trained using data generated as follows: a teacher model (Gemini3-Flash) produces 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 using parsed command semantics (operation type, target file, read range), not string equality. The top-3 most similar actions are averaged; a candidate passes if the average similarity score reaches 0.6. From passing candidates, the shorter version is selected as the training target. If all 8 candidates fail, the original observation becomes the target, teaching the model when to retain content.

Two-Stage Training: Offline Guidance and Online Alignment

Offline trajectories from an uncompressed agent have a hidden risk: during data collection the agent sees full history, but at deployment earlier steps are already compressed, altering the history distribution. CoACT addresses this with two stages: (1) supervised fine-tuning on offline trajectories to obtain an initial compressor; (2) online alignment where the compressor participates in actual agent runs, retaining previously compressed history, re-evaluating action preservation and length selection to produce a second dataset. The final compressor is trained on the merged data. Ablation shows offline-only training yields PASS@1 56.0% (vs. 57.0% uncompressed), while adding online data raises PASS@1 to 60.5% with similar token usage.

Experimental Results

Token Reduction and Task Performance

On 200 randomly sampled SWE-bench Verified instances, CoACT reduces token consumption across three models: Qwen3.5-35B-A3B from 3.795M to 2.428M, Deepseek-v4-Pro from 1.068M to 0.868M, Gemini3-Flash from 0.685M to 0.422M — an average 33.0% reduction. Average PASS@1 improves from 69.0% to 71.0% (Qwen +3.5, Gemini +4.0, Deepseek -1.5). Average interaction steps drop from 56.5 to 51.2. The proportion of observations exceeding 1K tokens falls from 32.3% to 9.4% on Qwen.

Comparison with Baselines

Against LLMLingua-2, SWE-Pruner, and LongCodeZip on Qwen: LLMLingua-2 drops PASS@1 to 50.0% and increases total tokens to 10.329M; SWE-Pruner raises tokens to 4.471M; LongCodeZip reduces to 3.165M. CoACT achieves 2.428M tokens with PASS@1 60.5%. 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.

Combination with History Compression (AgentDiet)

CoACT can complement history-rewriting methods. Alone, AgentDiet reduces 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 Availability

Paper: CoACT: Action-Preserving Observation Compression for Coding Agents (accepted at ICSE 2027, Top 5%).

ArXiv: https://arxiv.org/abs/2607.02911 Code:

https://github.com/THU-Agent/CoACT
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LLM AgentsSWE-benchCoding AgentToken ReductionICSE 2027Observation CompressionCoACTNAP
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.