Wink Pings

Agents No Longer Call Tools; They Write Code to Call Tools

Anthropic MCP paper: Same tools, same task, tool context dropped from 150,000 tokens to 2,000 tokens, time and cost reduced by 98.7%. The model didn't change; what changed was the calling method—the Agent no longer calls tools one by one, but writes code to call tools.

Anthropic engineers demonstrated an Agent optimization in an MCP paper: tool context dropped from 150,000 tokens (the text unit of language models) to 2,000 tokens. Same tools, same task. The model didn't change.

What changed was the calling method. The Agent no longer calls tools one by one; instead, it writes code and lets the code call tools.

Tools → Files → Code → Filtering → Answer.

This optimization has 6 parts:

1. Tools as files: Each MCP tool becomes a .ts file under ./servers. The Agent lists the folder and only opens what it needs.
2. On-demand loading: Tool definitions drop from 150,000 tokens to 2,000 tokens. Time and cost reduced by 98.7%.
3. Filter in code: A 10,000-row table is filtered in a sandbox. The model sees only 5 rows.
4. Loop in code: A loop polling Slack and other services for "deployment complete" runs as a while loop. Each check no longer goes through the model.
5. Redaction by default: Email addresses and phone numbers become [EMAIL_1] and [PHONE_1] before the model sees them. Real data still lands in Salesforce.
6. Skills: Usable code is saved to ./skills with a SKILL.md. The Agent builds its own toolbox.

rari (@0xwhrrari, AI researcher) called this paper a goldmine. He also cited his own long article, "Harness, Loop and Graph: The Enhanced Edition of Agent Engineering", breaking down the causes of Agent failure into three layers.

The long article starts with a common scenario:

Your Agent passed all the tests, the PR is open, and the issue is still open. No one lied. The Agent ran the tests it was given, in the repository it was given, according to the "done" rules it was given. The model finished its job. Everything around the model did not.

rari names "everything around the model":

Harness is space. What the Agent can see, touch, remember, and prove.
Loop is time. How the Agent tries, checks, retries, and stops.
Graph is structure. What steps exist, what flows between steps, and who decides the next step.

They nest: the model runs in the loop, the loop runs in the graph's nodes, and the graph runs in the harness. Before debugging an Agent, first determine which layer the fault is on. Editing the wrong file is a harness problem; repeating the same wrong solution six times is a loop problem; two steps waiting on each other is a graph problem.

This framework explains why code mode works.

In traditional MCP calls, every tool definition travels with every request. The more tools there are, the more bloated the context becomes. For an Agent loaded with all tools, before you've even asked any question, part of the window is already burned. Anthropic's term is attention budget: context is a limited resource, with diminishing marginal returns. Code mode rewrites the harness layer—tools go from definitions to files, from declarations to code. The Agent doesn't need to know all the tools; it needs the ability to find tools.

There are several worthwhile additions in the comments:

One user pointed out that Claude Code already experimentally supports this mode, v2.1.323+. Set CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1, and Claude will write a JS script to batch process tool calls rather than calling them one by one. The improvement is greatest for tasks involving many files.

Another user said the cheapest optimization is to simply turn off MCP servers you don't use. Tool definitions travel with every request; whether you use them or not, they burn tokens.

Another user looked further ahead: the harness will become obsolete; API, MCP, CLI, and Skill documentation will collapse into one bot; the skill definition is the contract, and the CLI is the brain. He gave an architecture diagram:

exoskeleton architecture diagram

There are also doubts. One user asked: the model only sees 5 rows, but did the filter code select the right 5 rows? The paper measured token savings but did not verify the filtering results. Another user warned: writing code to call tools shifts risk into the scripts, and generated scripts have no schema checks. Another user felt this is nothing new: Hermes Agent has long been executing code, keeping intermediate results in the sandbox, with only the final output returning to the model.

Whether it's new or not doesn't matter. What matters is that this pattern once again validates one thing: the bottleneck of an Agent is often not the model, but the system around the model. In rari's long article there is a sentence: the model suggests, the harness decides. Code mode moves a big step of decision-making power from the model to the harness. Tool context is the Agent's admission fee; Code mode lowers the admission fee from booking the entire venue to buying a ticket.

发布时间: 2026-11-22 06:03