Code Mode Could Cut AI Agent Context Tokens by 99% Over Classic Tool-Calling
A technique called Code Mode is emerging as an alternative to the traditional tool-calling approach used by most AI agents today. In the classic loop, every connected tool's schema and all intermediate data are streamed through the model's context window, which can balloon to hundreds of thousands or even millions of tokens on complex tasks. Code Mode instead lets the agent write a single script that runs inside a sandbox, keeping bulk data out of the context and returning only the final result to the model. A demonstration task involving 2,000 tickets and 400 customers showed context usage drop from 36,781 tokens to just 222 — a 99.4% reduction — while producing the same output. Both Anthropic and Cloudflare have begun adopting variants of this approach as AI agents are connected to increasingly large numbers of tools and APIs.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in