One Script, 26 Tool Calls, 99.2% Cheaper: What 'Code Mode' Really Saves
A production measurement from Agent Swarm shows that letting an agent run one script instead of 26 sequential tool calls cut a real workflow from an estimated $2.44 floor down to about two cents, and the saving dwarfs any difference between LLM providers.
Jul 25, 2026 · 4 min read
Key takeaways
Agent Swarm measured 'code mode' (one script call replacing 26 sequential tool calls) on a real production workflow: 25,811 characters reached the agent's context instead of an estimated ~3.26 million, a roughly 126x reduction.
Priced at Claude Sonnet 5's $3/M input-token rate, the script run cost about $0.02 versus a $2.44 floor for the raw sequential path, and the floor understates the real cost because raw results normally get re-sent on every subsequent turn.
The ~99.2% token reduction holds across providers: at five different models' own rates ($1.40 to $10 per million tokens), the script stayed under $0.07 while the raw path ranged from $1.14 to $8.15.
Because the reduction is architectural (avoiding what enters the model's context) rather than a pricing choice, it swamps the price gap between the cheapest and most expensive model tested, a roughly 7x price spread.
For agent-heavy products, the bigger cost lever is often what you let into context, not which provider you pick.
What is 'code mode' and what did Agent Swarm actually measure?
Instead of an agent making 26 separate tool calls (one per workflow, to check for failures) and holding every raw JSON result in its context, Agent Swarm's script runs all 26 calls itself, inside a sandboxed subprocess, and returns only a single distilled summary. They measured both paths directly on their real production catalog: the script's actual run (13.12 seconds, 25,811 characters) versus a measured-then-extrapolated estimate of what the same task would cost as 26 raw sequential tool calls (about 3.26 million characters).
How big is the saving, in dollars?
At Claude Sonnet 5's $3-per-million-input-token rate, the script cost roughly $0.02. The raw sequential path came in at a $2.44 floor, and the team is explicit that this is a floor, not a real total, since in an actual multi-turn agent loop, each of the 26 raw results would normally stay in context and get billed again on every following turn.
Does the saving hold across different LLM providers?
Yes, and this is the part worth internalizing: because the reduction is about what data ever reaches the model (roughly 126x fewer characters), the dollar saving scales with whatever rate you're paying. Agent Swarm priced the same two token counts across five models, from GLM-5.2 at $1.40 per million tokens to Fable 5 at $10 per million tokens, a more than 7x spread between the cheapest and priciest provider. Even at the cheapest rate, the raw path still cost over a dollar; even at the most expensive rate, the script stayed under seven cents.
What does this mean if you're optimizing LLM spend?
Shopping for a cheaper token rate is a real lever, worth roughly 7x in this example, but it's a much smaller lever than cutting what enters your context in the first place, worth roughly 126x here. If your product runs agents that fan out across many tool calls, the architecture question, does raw data need to touch the model's context at all, is worth answering before the provider question of which model is cheapest.
Architecture (what reaches the model's context) can save you an order of magnitude more than provider shopping ever will, and you can model both levers side by side in Calcaas before you commit to a rebuild.
Frequently asked questions
What is 'code mode' for AI agents?
It's a pattern where an agent runs a script that makes many tool calls internally, inside a sandbox, and returns only a distilled result, instead of making each tool call directly and holding every raw response in its context.
How much cheaper was code mode in this measurement?
Agent Swarm measured about a 99.2% reduction in characters reaching the agent's context (roughly 126x fewer), which translated to about $0.02 versus a $2.44 cost floor for the raw sequential-calls approach, priced at Claude Sonnet 5's rate.
Does the saving depend on which LLM provider you use?
The percentage reduction is model-invariant since it comes from cutting the volume of data entering context, but the dollar amount scales with the provider's price. Agent Swarm found the script stayed cheap (under $0.07) across five providers ranging from $1.40 to $10 per million tokens.
Is the $2.44 'raw path' number a real cost or an estimate?
It's described as a floor: fully measured up to a point, then extrapolated from sampled data, and it only counts the tokens once. In a real multi-turn agent conversation, the same raw results would typically be re-sent on every following turn, making the real cost higher. (Place the JSON-LD block above inside a <script type="application/ld+json"> tag in the page head.)