Microsoft Research Open-Sources TokenEconomizer for Coding Agents
Cost savings that accumulate with repository experience, rather than a fixed discount, mean long-lived codebases benefit most — an implicit argument that context should be treated as per-repo infrastructure. Teams running agents repeatedly on the same monorepo can plug it in without touching their agent or model, and the open-source plugin stops at alerting the developer after a second stall, keeping humans in the loop. It contrasts with blunt approaches like lowering reasoning effort, which saves money but hurts accuracy.
Microsoft Research has open-sourced TokenEconomizer, an external controller that cuts token costs for coding agents without modifying the agent or the underlying model. It was built with UC Berkeley and Microsoft Security, with code on GitHub and a blog post on microsoft.com. The system learns from a repository's historical agent sessions to eliminate repeated exploration and wasted tool calls.
The team analysed 60 Claude Code tasks on SWE-Bench and found that once a repository accumulates at least 5 tasks, about 30% of tool calls merely repeat earlier work, versus roughly 7% across different repos. Each round loaded 23 tool descriptions, 16 of which were never invoked; failed tasks were 17% of runs but about 32% of spend. TokenEconomizer works at the agent's periphery: it distils one-line micro-skills from multi-turn trajectories (confirmed only across non-overlapping file changes and retired on contradictory evidence), prunes rarely used tools while keeping core shell and file access, and intervenes when the agent is stuck. In the Django example, first-request prompt tokens dropped from roughly 42,000–46,000 to about 15,000–16,000.
Across 277 SWE-Bench tasks, 6 repos and 5 agent-model combinations, cost fell 18.4% to 30.9% versus the default strong-reasoning setting, with all 30 repo-combination pairs cheaper; four combinations improved Pass@1 and Opus 4.8 dropped only about 1.0 point. Simply lowering reasoning effort also saves money but costs accuracy, whereas this approach keeps success rates largely stable.
微软研究院开源 TokenEconomizer:不改模型,从仓库经验里给 Coding Agent 省 token @MSFTResearch 研究并开源了一套外部控制器「TokenEconomizer」:不改 Coding Agent 和底层模型,从同一仓库的历史会话里学习,减少重复摸索和无效调用。 博客地址: microsoft.com/en-us/research… 开源地址: github.com/microsoft/Toke… # 浪费主要出在反复从零开始 开发者常在同一仓库多次调用 Coding Agent,但 Agent 往往每次重新摸索测试命令、加载用不到的工具,并在失败路径上打转。团队对 Claude Code 在 SWE-Bench 上 60 个任务的剖析显示:同一仓库累计至少 5 个任务后,约 30% 的工具调用在重复更早任务;跨仓库对照只有约 7%。每轮会加载 23 个工具说明,其中 16 个从未被调用。失败任务只占 17%,却占支出约 32%。固定的省钱插件在有的仓库能省,在有的仓库反而更贵,说明控制策略需要按仓库适应。 # 三种机制都作用在 Agent 外围 TokenEconomizer 由加州大学伯克利分校、微软研究院和 Microsoft Security 开源。它读取会话日志、更新仓库状态,再通过已有接口起作用:把微技能写入起始上下文、裁剪工具列表,并在卡住时干预。控制器自己的模型调用也计入成本。 微技能从多轮轨迹里提炼一行级的仓库操作知识,例如在 SymPy 中直接用原生测试,而不必先找 pytest。这类知识要在多项任务、且改动文件不重叠的情况下被确认后才会注入;出现矛盾证据则永久退役。 工具裁剪会去掉长期不用的工具,同时保留核心的命令行和文件读写,并定期全量回放,以免误删。文中 Django 的例子显示,首次请求的提示 token 可从约 4.2 万至 4.6 万降到约 1.5 万至 1.6 万。 卡住时的干预则根据历史成功轮次设置预算。论文实验里,判定卡住后可先改方向,二次卡住后终止任务;开源插件在二次卡住后是提醒开发者,不会自行停掉任务。 # 省钱随经验积累,成功率大体稳住 在 SWE-Bench 的 277 个任务、6 个仓库、5 组 Agent 与模型组合上,相对默认的较强推理设置,平均费用下降 18.4% 至 30.9%,30 个「仓库×组合」全部变便宜。一次尝试成功率(Pass @1 )有四组上升,Opus 4.8 仅下降约 1.0 个百分点。如果只是调低推理强度,也能省钱,但成功率会下降 1.8 至 10.3 个百分点。 节省是逐渐显现的:多数仓库前几项任务可能更贵,到第 6 个任务起,累计费用才转便宜。拆开来看,工具裁剪贡献最大,微技能次之,卡住干预更小。Web-Bench 上费用约降 16.0% 至 21.2%;跨新仓库的安全审计约降 6.4% 至 19.6%。没有仓库连续性时,微技能会被关掉。 Microsoft Research @MSFTResearch AI coding agents can waste time and tokens relearning the same lessons. TokenEconomizer builds on past sessions to cut costs while maintaining task success. It’s a path toward coding agents that learn not only how to solve tasks, but also how to spend computation more effectively. The open-source plugin is available now on @github . msft.it/6017xDtyc
This report is categorized under AITOP's "Products" desk, focusing on US frontier AI labs and Silicon Valley technology leaders. Within our cross-regional analytical framework, it directly maps to AI developer toolchains, coding agents, and engineering workflows and US-China foundation model benchmarks and commercialization comparison. Key entities and technical topics under continuous tracking include TokenEconomizer, Claude Code, Microsoft Research, coding assistants.
Source attribution: curated from shao__meng (@shao__meng).