AI guides

CoACT compresses tool outputs to preserve next actions and reduce token use in tests

By 机器之心0 viewsSource: 机器之心
CoACT observation compression and next-action preservation framework

A Tsinghua team evaluates compression on 200 SWE-bench Verified instances with three models, reporting a 33.0% average reduction in total token use and broadly similar task success.

The longer a Coding Agent's context, the higher the cost of each call. Can the context be compressed without affecting task completion?

When a Coding Agent solves software problems, it repeatedly reads code, modifies programs, and runs tests. File contents, search results, and logs returned at each step remain in the context and must be carried along in full for the next call. The harder the task, the longer the context, the more tokens each step processes, and the higher the cost. Analysis found that these observations account for 45.7% of total token consumption on SWE-bench Verified and as much as 67.8% on Terminal-Bench.

Can these observations be compressed directly? The difficulty is knowing, at compression time, whether the removed content will be needed later.

A team from Tsinghua University's School of Artificial Intelligence proposes CoACT, an observation-compression method for Coding Agents. It does not judge compression by how closely the result resembles the original, but by whether the Agent's next action changes after compression. On 200 SWE-bench Verified instances and three Agent models, CoACT reduces total token consumption by an average of 33.0%, while mean PASS@1 goes from 69.0% to 71.0%, with task performance close to the uncompressed setting. The work has already received direct acceptance at ICSE 2027, a CCF Class A conference (Top 5%).

Article illustration

  • Paper title: CoACT: Action-Preserving Observation Compression for Coding Agents

  • Paper: https://arxiv.org/abs/2607.02911

  • Code: https://github.com/THU-Agent/CoACT

1. Limitations of existing compression methods

Existing methods broadly follow two routes. One rewrites history: sliding windows discard older commands and outputs, while AgentDiet has the model periodically revisit the history and delete content that is repetitive or not useful. Once history has been rewritten, however, the original KV Cache cannot be reused in full. The model must prefill the rewritten content again, so fewer tokens do not necessarily mean lower cost.

The other route compresses a new observation before it enters the context. Previous history stays untouched, and the cache can be reused as usual. This is the KV Cache-friendly route CoACT chooses.

Taking this route first requires clarifying the goal of compression. The Agent's purpose is to complete the task, so compression should be judged by whether the task can still be completed. The objective is therefore to minimize total token consumption while keeping task success (PASS@1) close to that of the uncompressed Agent.

This requires balancing two sides: removing too much may deprive the Agent of necessary information, causing task failure or repeated reading; removing too little will not effectively reduce overhead.

2. The core idea: Next-Action Preservation (NAP)

The most direct validation would be to let the Agent read the compressed result and finish the task. But the same observation can have many possible compressions, and running each through the entire task is too expensive. A task also involves many compression steps, making it difficult to identify which compression caused the final outcome.

We view Agent execution as a loop of "read output, perform an action, obtain new output." Assuming identical initial environments and identical environmental responses to the same actions, if the Agent's next action stays unchanged after every compression, the environment receives the same operations and returns the same results. In theory, the subsequent action sequence and final outcome will then stay unchanged too.

Based on this reasoning, we propose Next-Action Preservation (NAP): hold the task objective and history constant, let the Agent read the original and compressed observations separately, and compare its next actions. For example, after reading some code, the Agent originally plans to inspect a function called inside it. If it still inspects that function after reading the compressed result, the compression is considered to preserve the next action. This lets each compression be tested individually, without waiting until the task ends.

3. How to construct training data:

Building compression demonstrations with NAP

With NAP, we train a lightweight compressor based on Qwen3.5-4B. The process has several steps:

First, teacher model Gemini3-Flash generates 8 candidate compressions of the same observation. The Agent then samples repeatedly from the original observation to obtain 8 reference actions. The action elicited by each compression is compared with the reference actions one by one; the 3 most similar scores are averaged, and a score of at least 0.6 is required to pass. The comparison does not simply compare strings: it parses the command's operation type, target file, and reading range. Commands written differently but reading the same code segment are recognized as the same operation.

After these checks, shorter versions among those that pass are selected as training demonstrations. If all 8 candidates fail, the original observation becomes the target, teaching the model to keep content when it needs to be kept.

4. Two-stage training: offline guidance and online alignment

Constructing data only from uncompressed Agent trajectories has a hidden risk: during collection, the Agent's history is complete, but after deployment, content read in earlier steps has also been compressed, so the history it sees is already different.

CoACT first performs supervised fine-tuning on offline trajectories to obtain an initial compressor. In the second stage, that compressor actually participates in Agent runs, retaining the previously compressed history and repeating action comparisons and length selection to obtain a second dataset. The two stages' data are finally combined to train the final compressor.

Article illustration

In a controlled experiment, the compressor trained only on offline data has PASS@1 of 56.0%, slightly below the uncompressed 57.0%. Adding second-stage online data raises it to 60.5%, with broadly comparable total token consumption.

Article illustration

5. Experimental results: one-third saved, performance unchanged

On 200 randomly selected SWE-bench Verified instances, CoACT reduces token consumption for all three models, Qwen3.5-35B-A3B, Deepseek-v4-Pro, and Gemini3-Flash: Qwen goes from 3.795M to 2.428M, Deepseek from 1.068M to 0.868M, and Gemini from 0.685M to 0.422M, for a reported mean reduction of 33.0%. The three models' mean PASS@1 changes from 69.0% to 71.0%: Qwen and Gemini improve by 3.5 and 4.0 percentage points, respectively, while Deepseek drops slightly by 1.5 points. Mean interaction steps also fall from 56.5 to 51.2.

Article illustration

After compression, long, bulky observations become noticeably less common. On Qwen3.5-35B-A3B, the share of observations longer than 1K tokens falls from 32.3% to 9.4%.

The comparison with existing observation-compression methods is more interesting. For Qwen, LLMLingua-2 reduces PASS@1 from 57.0% to 50.0%, but total tokens rise from 3.795M to 10.329M. SWE-Pruner raises them to 4.471M; LongCodeZip lowers them to 3.165M; CoACT uses 2.428M with PASS@1 of 60.5%. On Deepseek, all three baselines use more than the uncompressed 1.068M total tokens, while CoACT lowers the total to 0.868M, the lowest among the methods on both evaluation models. This shows that simply targeting shorter observations does not guarantee lower total overhead for the whole task.

Article illustration

As a single-step compression method, CoACT can also work with history-compression methods. With AgentDiet alone, total tokens decrease, but estimated total cost rises from the uncompressed $41.26 to $45.65 because rewriting history affects KV Cache reuse. Applying CoACT first within the AgentDiet workflow lowers estimated total cost to $25.88 while keeping task success similar, about 43.3% less than AgentDiet alone.

Article illustration

About the authors

This research was completed by the AI Agent research group at Tsinghua University's School of Artificial Intelligence. Corresponding author Jia Li is an assistant professor at the school, focusing mainly on AI + software and trustworthy agents. First author Haorui Chen is expected to enter the school's direct-entry PhD program in 2027, with a research focus on Efficient AI.

This article comes from the WeChat official account "Synced," by "Synced."

Related topics

After reading

Join the AINRK community

Read how to join the community and connect with people working in AI.

Community information (opens in a new tab)