微软发布TokenEconomizer插件,编码Agent成本降低30.9%
Meet TokenEconomizer: Microsoft’s Plugin That Cuts Coding Agent Costs by Up to 30.9%
做AI编程开发的同学必看,实测能降三成成本且无需改模型,直接装插件即可压测你的Agent链路。
A team of researchers from Microsoft Research and UC Berkeley have released TokenEconomizer, an open-source cost controller for coding agents. TokenEconomizer is a plugin that learns from past sessions in a repository to cut waste in later ones. It works with Claude Code, Codex, GitHub Copilot CLI and Pi. It does not touch model weights or agent code. On 277 SWE-Bench tasks, it lowered mean cost by 18.4% to 30.9% across 5 agent-model settings.
微软研究院与加州大学伯克利分校的研究团队发布了 TokenEconomizer,这是一款面向编码代理的开源成本控制器。TokenEconomizer 是一个插件,它通过学习仓库中的历史会话来减少后续会话中的资源浪费。它与 Claude Code、Codex、GitHub Copilot CLI 和 Pi 兼容。它不修改模型权重或代理代码。在 277 个 SWE-Bench 任务中,它在 5 种代理-模型配置下将平均成本降低了 18.4% 至 30.9%。
TL;DR
TL;DR(太长不看)
- Package: A standard-library Python package and agent plugins, with 3 switchable mechanisms.
- Runs on: Any machine running Claude Code, Codex, Copilot CLI or Pi with Python 3.10+. No GPU and no API key of its own.
- Performance: 18.4% to 30.9% lower mean SWE-Bench cost, and cheaper in all 30 repository-setting cells.
- Best: 30.9% lower cost on Claude Code with Opus 4.8 (33.2% when combined with RTK).
- Worst: Only 6.4% to 9.3% savings on ReposVul audits; Pass@1 drops 1.0 point on Opus 4.8.
- 包:一个标准库 Python 包及代理插件,包含 3 种可切换机制。
- 运行环境:任何运行 Claude Code、Codex、Copilot CLI 或 Pi 且配备 Python 3.10+ 的设备。无需 GPU,也无需其专属 API 密钥。
- 性能表现:SWE-Bench 平均成本降低 18.4% 至 30.9%,在所有 30 个仓库-设置组合中均更便宜。
- 最佳效果:在 Opus 4.8 配合 Claude Code 时,成本降低 30.9%(若结合 RTK 则降低 33.2%)。
- 最差效果:在 ReposVul 审计中仅节省 6.4% 至 9.3%;Opus 4.8 上的 Pass@1 指标下降 1.0 分。
Why do coding agents waste tokens?
为什么编码代理会浪费 token?
Every agent turn re-bills the system prompt, every loaded tool schema and the full history. The research team profiled 60 SWE-Bench tasks across 6 repositories using Claude Code with Opus 4.8. They found 3 recurring sources of waste:
每次代理交互都会重新计费系统提示词、每个加载的工具模式以及完整的历史记录。研究团队使用 Opus 4.8 配合 Claude Code,对跨越 6 个仓库的 60 个 SWE-Bench 任务进行了画像分析。他们发现了 3 种反复出现的浪费来源:
- Repeated discovery: once 5 tasks precede the current one, 30% of tool calls repeat an earlier action.
- Unused tools: 23 tool schemas load every turn. 16 are never called, and 3 cover 98% of calls.
- Failure loops: 10 failed runs were 17% of tasks but 32% of total spend.
- 重复发现:一旦前 5 个任务先于当前任务执行,30% 的工具调用会重复之前的操作。
- 未使用的工具:每次交互都加载 23 个工具模式。其中 16 个从未被调用,而 3 个覆盖了 98% 的调用。
- 失败循环:10 次失败运行占任务的 17%,但占总支出的 32%。
They also tested 3 fixed open-source strategies: RTK, Serena and Aider’s RepoMap. None was cheaper everywhere. All 3 cut cost on Django and raised it on SymPy.
他们还测试了 3 种固定的开源策略:RTK、Serena 和 Aider 的 RepoMap。没有任何一种策略在所有场景下都更便宜。这 3 种策略在 Django 上降低了成本,但在 SymPy 上却增加了成本。
How does TokenEconomizer work?
TokenEconomizer 是如何工作的?
TokenEconomizer is an external controller that treats the agent as a black box. It keeps a state per repository, built from completed traces. Before each task, it sets 3 policies through the prompt, the tool settings and the event stream.
TokenEconomizer 是一个外部控制器,它将代理视为黑盒。它基于已完成的轨迹为每个仓库维护状态。在每个任务开始前,它通过提示词、工具设置和事件流设定 3 项策略。
1. Micro-skills
1. 微技能
An LLM proposer turns trace digests into 1-line facts, such as the working test command. Each fact carries regex detectors that check later traces without a model call. A fact enters the prompt after 3 confirmations on tasks with non-overlapping edited files. Its need rate must also stay at or above 0.4. One contradiction counts as 5 confirmations, so wrong facts retire quickly.
LLM 提议者将轨迹摘要转化为单行事实,例如有效的测试命令。每个事实都携带正则表达式检测器,用于在不调用模型的情况下检查后续轨迹。对于编辑文件不重叠的任务,一个事实需经过 3 次确认才会进入提示词。其需求率也必须保持在 0.4 或以上。一次矛盾相当于 5 次确认,因此错误的事实会被快速淘汰。
2. Tool pruning
2. 工具剪枝
Shell, read, write and edit tools are always kept. Other tools are masked after 3 consecutive unused tasks, or when an LLM judge marks them irrelevant. The full catalog returns every 5 tasks for a re-audit. On Django with Claude Code, the first request on task 2 fell from 43,351 to 16,295 prompt tokens.
Shell、read、write 和 edit 工具始终保留。其他工具在连续 3 个任务未使用后,或被 LLM 判定为不相关时会被屏蔽。完整目录每 5 个任务返回一次以供重新审计。在 Django 项目中使用 Claude Code 时,任务 2 的首次请求提示词 token 数从 43,351 降至 16,295。
3. Failure-loop intervention
3. 失败循环干预
The controller learns a turn budget: 1.25 times the 90th percentile of successful run lengths. Cheap rule checks flag repeated failures or dense errors. An LLM judge then decides if the agent is stuck, at 0.7 confidence or higher. A stuck agent gets 1 redirect, then a stop if the loop recurs.
控制器学习一个回合预算:成功运行长度的第 90 百分位数的 1.25 倍。低成本规则检查可标记重复失败或密集错误。随后由 LLM 判定器判断代理是否陷入停滞,置信度需达到 0.7 或以上。陷入停滞的代理获得 1 次重定向机会,若循环再次发生则停止。
What do the SWE-Bench results show?
SWE-Bench 的结果显示了什么?
| Setting | Cost vs default | Pass@1 default | Pass@1 TokenEconomizer |
|---|---|---|---|
| Claude Code + Sonnet 5 | -23.6% | 74.7 | 76.0 |
| Claude Code + Opus 4.8 | -30.9% | 74.0 | 73.0 |
| Codex + GPT-5.6 Terra | -24.7% | 73.8 | 74.7 |
| Codex + GPT-5.6 Sol | -26.1% | 80.1 | 81.7 |
| Copilot CLI + Sonnet 5 | -18.4% | 75.0 | 77.6 |
| 设置 | 相对于默认值的成本 | Pass@1 默认值 | Pass@1 TokenEconomizer |
|---|---|---|---|
| Claude Code + Sonnet 5 | -23.6% | 74.7 | 76.0 |
| Claude Code + Opus 4.8 | -30.9% | 74.0 | 73.0 |
| Codex + GPT-5.6 Terra | -24.7% | 73.8 | 74.7 |
| Codex + GPT-5.6 Sol | -26.1% | 80.1 | 81.7 |
| Copilot CLI + Sonnet 5 | -18.4% | 75.0 | 77.6 |
Source: arXiv 2610.22732, Table 1. Costs include all controller calls. 3 seeds per setting.
来源:arXiv 2610.22732,表 1。成本包含所有控制器调用。每个设置使用 3 个种子。
Pass@1 improved in 4 of 5 settings. Lower reasoning effort saved cost but cut Pass@1 by 1.8 to 10.3 points. RTK alone raised cost in 12 of 30 repository-setting cells, and RepoMap in 15.
Pass@1 在 5 个设置中的 4 个得到提升。降低推理努力节省了成本,但使 Pass@1 下降了 1.8 到 10.3 个百分点。仅 RTK 在 30 个仓库-设置单元格中有 12 个导致成本上升,RepoMap 则有 15 个。
Savings build over time. Most repositories cost more at first, but all were cheaper by the sixth task. Alone on Claude Code, tool pruning saved 13.2% to 17.7%, micro-skills 11.8% to 14.3%, and the loop guard 5.4% to 7.1%.
节省随时间累积。大多数仓库起初成本更高,但在第六个任务时全部变得更便宜。仅在 Claude Code 上,工具修剪节省了 13.2% 至 17.7%,微技能节省了 11.8% 至 14.3%,循环守卫节省了 5.4% 至 7.1%。
Results also held outside SWE-Bench. Costs fell 16.0% to 21.2% on Web-Bench and 16.5% to 19.6% on CredData. ReposVul saw only 6.4% to 9.3%, because shorter runs leave less to remove.
结果在 SWE-Bench 之外同样成立。Web-Bench 上的成本下降了 16.0% 至 21.2%,CredData 上下降了 16.5% 至 19.6%。ReposVul 仅下降 6.4% 至 9.3%,因为较短的运行周期意味着可移除的内容较少。
How does it compare with other token-saving tools?
它与其他节省 token 的工具相比如何?
| Feature | TokenEconomizer | RTK | Serena | Aider RepoMap |
|---|---|---|---|---|
| Approach | Learns per-repository policies from past sessions | Compresses shell command output | MCP server with symbol-level code tools | Ranked map of repository symbols in the prompt |
| Learns from earlier tasks | Yes | No | No | No |
| License | Apache 2.0 | Apache 2.0 CLI; BUSL-1.1 engine | GPL-3.0-or-later (MIT for SolidLSP) | Apache 2.0 |
| Agents | Claude Code, Codex, Copilot CLI, Pi | 18 AI coding tools | Any MCP client | Aider |
| Mean SWE-Bench cost change (paper, 5 settings) | -18.4% to -30.9% | -8.9% to +4.5% | Not in main runs (raised pooled cost in profiling) | -6.1% to +6.5% |
| Cells with higher cost (of 30) | 0 | 12 | Not disclosed | 15 |
| 功能 | TokenEconomizer | RTK | Serena | Aider RepoMap |
|---|---|---|---|---|
| 方法 | 从过往会话中学习针对每个仓库的策略 | 压缩 shell 命令输出 | 具有符号级代码工具的 MCP 服务器 | 提示词中按排名排列的仓库符号映射 |
| 从早期任务中学习 | 是 | 否 | 否 | 否 |
| 许可证 | Apache 2.0 | Apache 2.0 CLI;BUSL-1.1 引擎 | GPL-3.0-or-later(SolidLSP 为 MIT) | Apache 2.0 |
| 代理 | Claude Code, Codex, Copilot CLI, Pi | 18 种 AI 编码工具 | 任何 MCP 客户端 | Aider |
| 平均 SWE-Bench 成本变化(论文,5 个设置) | -18.4% 至 -30.9% | -8.9% 至 +4.5% | 未在主要运行中显示(在分析中提高了汇总成本) | -6.1% 至 +6.5% |
| 成本更高的单元格(共 30 个) | 0 | 12 | 未披露 | 15 |
Cost rows: TokenEconomizer paper. Licenses and claims: each project’s repository or docs.
成本行:TokenEconomizer 论文。许可证和声明:各项目的仓库或文档。
How do you install TokenEconomizer?
如何安装 TokenEconomizer?
The plugin needs one of the 4 agents and Python 3.10 or newer. On Claude Code, clone the repo, add it as a marketplace, then run claude plugin install tokeneconomizer@tokeneconomizer. Learned data stays local in ~/.tokeneconomizer. Tool pruning and the loop guard are on by default. Micro-skills are off by default, because the proposer adds model calls.
该插件需要以下四种代理之一,以及 Python 3.10 或更高版本。在 Claude Code 中,克隆仓库,将其添加为市场(marketplace),然后运行 claude plugin install tokeneconomizer@tokeneconomizer。学习数据保留在本地 ~/.tokeneconomizer 目录中。工具剪枝和循环守卫默认开启。微技能(Micro-skills)默认关闭,因为提议者会引入模型调用。
Key Takeaways
关键要点
- TokenEconomizer cuts SWE-Bench cost 18.4% to 30.9% with an unchanged agent.
- It was cheaper in all 30 repository-setting cells; RTK and RepoMap were not.
- Tool pruning is the biggest single lever, at 13.2% to 17.7%.
- Pass@1 rose in 4 of 5 settings and fell 1.0 point on Opus 4.8.
- It is Apache 2.0 and installs on Claude Code, Codex, Copilot CLI and Pi.
- TokenEconomizer 在不改变代理的情况下,将 SWE-Bench 的成本降低了 18.4% 至 30.9%。
- 在所有 30 个仓库设置单元格中,它的成本都更低;而 RTK 和 RepoMap 则不然。
- 工具剪枝是最大的单一杠杆,可降低 13.2% 至 17.7% 的成本。
- Pass@1 在 5 种设置中的 4 种下有所提升,但在 Opus 4.8 上下降了 1.0 分。
- 它采用 Apache 2.0 许可证,可安装在 Claude Code、Codex、Copilot CLI 和 Pi 上。
Check out the Paper, GitHub Repo and Project Page. Also, feel free to follow us on Twitter and don’t forget to join our 150k+ML SubReddit and Subscribe to our Newsletter. Wait! are you on telegram? now you can join us on telegram as well.
查看论文、GitHub 仓库和项目页面。此外,欢迎在 Twitter 上关注我们,别忘了加入我们拥有 15 万+成员的 ML SubReddit,并订阅我们的新闻通讯。等等!你在 Telegram 上吗?现在你也可以加入我们的 Telegram 群组。
更进一步:量化金融体系
看懂新闻只是起点——沿量化金融路径,把它变成能交付的工程能力