Tsinghua's CoACT Cuts Coding Agent Token Costs by 33 Percent
A team from Tsinghua University's Institute for AI proposes CoACT, an observation compression method for coding agents that optimizes for preserving the agent's next action rather than textual similarity to the original context, avoiding removal of information needed later. Across 200 SWE-bench Verified instances and three agent models, CoACT cuts total token consumption by 33.0% on average while PASS@1 moves from 69.0% to 71.0%, keeping task performance essentially intact. The work was accepted directly to ICSE 2027, a CCF-A conference.
Related Entities
Full Report

Can context be compressed without affecting task completion?
The longer a Coding Agent's context, the higher the cost of each step's invocation. Can context be compressed without affecting task completion?
When a Coding Agent solves a software problem, it needs to repeatedly inspect code, modify programs, and run tests: the file contents, search results, and logs returned at each step all remain in the context, and must be carried in full again on the next round of invocation. The harder the task, the longer the context, and the more tokens each step must process, the higher the cost. Statistics show that on SWE-bench Verified, these observations account for 45.7% of total token consumption, and on Terminal-Bench they reach as high as 67.8%.
Can these observations be compressed directly? The difficulty is that during compression it is hard to know whether the removed content will be needed later.
A team from the Institute for Artificial Intelligence at Tsinghua University proposed CoACT: an observation compression method for Coding Agents. It does not judge whether the compressed result resembles the original text, but whether the Agent's next action changes after compression. On 200 instances of SWE-bench Verified and three Agent models, CoACT reduces total token consumption by an average of 33.0%, with average PASS@1 going from 69.0% to 71.0%, achieving task performance comparable to the uncompressed case. This work has been directly accepted by the CCF A conference ICSE 2027 (Top 5%).

-
Paper title: CoACT: Action-Preserving Observation Compression for Coding Agents
-
Paper link: https://arxiv.org/abs/2607.02911
-
Code address: https://github.com/THU-Agent/CoACT
- Limitations of existing compression methods
Existing methods fall roughly into two approaches. One is rewriting history: sliding windows discard earlier commands and outputs, while AgentDiet has the model periodically review history and delete repetitive or unused content itself. But once history is rewritten, the original KV Cache can no longer be fully reused, and the model must re-prefill the rewritten content; fewer tokens do not necessarily mean lower cost.
The other approach compresses new observations before they enter the context. Prior history remains untouched, and the cache is reused as usual. CoACT chooses this KV Cache-friendly path.
On this path, one must first clarify the goal of compression. The Agent's purpose is to complete the task, so the effect of compression should be measured by whether the task can be completed. Therefore the goal is: to reduce total token consumption as much as possible while keeping task success rate (PASS@1) close to that of the uncompressed Agent.
This requires a trade-off in two respects: too much deletion may leave the Agent lacking necessary information, causing task failure or repeated reads; too little deletion fails to effectively reduce cost.
- Core idea: Next-Action Preservation (NAP)
The most direct way to verify is to let the Agent read the compressed result and run the task to completion. But the same observation can have many compressions, and running each to completion is too costly; a single task also requires many compressions, making it difficult to determine which compression caused the final result.
We believe the Agent's execution process can be viewed as a loop of "read output, execute action, obtain new output." Assuming the initial environment is the same and the environment responds identically to the same actions, then as long as the Agent's next action remains unchanged after each compression, the operations received by the environment and the results returned are the same, and the subsequent action sequence and final result will theoretically also remain unchanged.
Based on this derivation, we propose Next-Action Preservation (NAP): keeping the task goal and history the same, let the Agent read the observation before and after compression respectively, and then compare its subsequent actions. For example, after reading a piece of code, the Agent originally intended to inspect a function called within it; if after switching to the compressed result it still inspects this function, then this compression is considered to have preserved the next action. This allows each compression to be checked individually, without waiting until the task ends.
- How to construct training data:
Constructing compression demonstrations based on NAP
With NAP, we trained a lightweight compressor (based on Qwen3.5-4B). The approach proceeds in several steps:
First, let the teacher model Gemini3-Flash generate 8 compression candidates for the same observation; then let the Agent sample multiple times under the original observation to obtain 8 reference actions. The action elicited by each compression result is compared one by one with the reference actions, and the 3 most similar are averaged; a score of at least 0.6 is required to pass. The comparison is not string-based but parses the command's operation type, target file, and read range, so commands written differently but reading the same piece of code are recognized as the same operation.
After passing the check, the shorter version is selected as the training demonstration. If all 8 candidates fail, the original observation is used as the target, so the model learns to retain when it should.
- Two-stage training: offline guidance and online alignment
Constructing data solely from uncompressed Agent trajectories has a hidden risk: when collecting data, the Agent's history is always complete; but after actual deployment, the content read in the first few steps has also been compressed, so the history it sees is already different.
CoACT works as follows: in the first stage, it performs supervised fine-tuning on offline trajectories to obtain an initial compressor; in the second stage, it lets the compressor actually participate in Agent runs, retains the previously compressed history, and redoes action comparison and length filtering to obtain a second batch of data; finally, it merges the data from both stages to train the final compressor.

In the controlled experiment, the compressor trained only on offline data achieved a PASS@1 of 56.0%, slightly lower than the 57.0% of the uncompressed baseline; after adding the online data from the second stage, it rose to 60.5%, with total token consumption essentially unchanged.

- Experimental Results: One-Third Saved, Performance Unchanged
On 200 randomly sampled instances from SWE-bench Verified, CoACT reduced token consumption on all three models: Qwen3.5-35B-A3B, Deepseek-v4-Pro, and Gemini3-Flash. Qwen dropped from 3.795M to 2.428M, Deepseek from 1.068M to 0.868M, and Gemini from 0.685M to 0.422M, an average reduction of 33.0%. The average PASS@1 of the three models changed from 69.0% to 71.0%: Qwen and Gemini improved by 3.5 and 4.0 points respectively, while Deepseek dropped slightly by 1.5 points. The average number of interaction steps also fell from 56.5 to 51.2.

After compression, those long and space-consuming observations became noticeably fewer: on Qwen3.5-35B-A3B, the proportion of observations exceeding 1K tokens dropped from 32.3% to 9.4%.
Compared with existing observation compression methods, the gap is even more interesting. Taking Qwen as an example, after LLMLingua-2 compression, PASS@1 dropped from 57.0% to 50.0%, while total tokens instead rose from 3.795M to 10.329M; SWE-Pruner rose to 4.471M; LongCodeZip dropped to 3.165M; CoACT reached 2.428M with a PASS@1 of 60.5%. On Deepseek, the total tokens of all three baselines were higher than the uncompressed 1.068M, while CoACT dropped to 0.868M, making it the method with the lowest total tokens on both evaluated models. This shows that merely aiming to shorten observation length does not guarantee a reduction in the overall cost of the entire task.

As a single-step compression method, CoACT can also work in conjunction with history compression methods. When AgentDiet was used alone, although total tokens decreased, the estimated total cost rose from $41.26 uncompressed to $45.65, because rewriting history affected KV Cache reuse. By adding CoACT first into the AgentDiet pipeline, the estimated total cost dropped to $25.88, with task success rates remaining similar, about 43.3% less than using AgentDiet alone.

About the Authors
This research was completed by the AI Agent research group at the Institute for Artificial Intelligence, Tsinghua University. The corresponding author is Assistant Professor Li Jia from the Institute for Artificial Intelligence, Tsinghua University, whose main research directions are AI + software and trustworthy agents. The first author, Chen Haorui, is a 2027 direct-entry doctoral student (incoming) at the Institute for Artificial Intelligence, Tsinghua University, whose main research direction is Efficient AI.

© THE END
For reprinting, please contact this official account for authorization.
Submissions or report requests: [email protected]