HeadlinesBriefing HeadlinesBriefing.com

Code Mode vs Tool Calling Cost Speed Benchmarks

Towards Data Science •
×

For agent builders with many MCP integrations, Code Mode was 120x cheaper and 18x faster on 100-item fan-outs but less reliable on single lookups. The post Code Mode vs. Tool Calling Benchmarks Find a 16-Tool Crossover appeared first on Towards Data Science.

Table of contents

1. The problem with current agent behavior

What you will get from this article

2. What tool calling is — and where the cost comes from

3. Code Mode: moving the work out of the context window

4. The three flavors of Code Mode

5. Experiment Four conditions Task templates Ground truth Limitation

6. Results

6.1 Axis 1 — The single-step lookup and chain tasks

6.2 Axis 2 — fan-out tasks

6.3 Success rate results

7. The numbers tested on small models

8. When to use Code Mode

9. Code Mode limitations

9.1 Runtime failures

9.2 Security

9.3 Final words

10. References

The problem with current agent behavior LLM context windows keep getting longer. But it has been shown that model performance drops as the input context grows longer, and it is better to keep the context window a decent size. The problem is that in the real world, the agent must load the context of the task, skills, and all the tool descriptions in the system. It can reach 150,000 tokens in each call, which is a huge number that can cause the agent to work in an inefficient way. To fix this problem, Cloudflare enabled the model to write code that calls the tools whenever they are needed, and named this method Code Mode (Cloudflare). Anthropic later published a parallel approach. From Anthropic’s worked example, they have about a 98.7% reduction from 150k to about 2,000 tokens. Figure 1 — Tool definitions consumed 75% of the context window.

For a simple one-step task, Code Mode is worth using if we have more than about 16 tools, where the difference is visible. If the number is lower than 16, normal tool-calling is generally cheaper, faster, and more reliable. For repetitive tasks, Code Mode can work well even on the smallest scale. It is about 120x cheaper for 100 items. For multi-step tasks where the result of each step is needed as input for the next, there was no specific crossover point, but the advantage was much more dependent on task structure. As a simple rule of thumb, when you switch to Code Mode, you should count your tools and estimate your workload.

Source: Towards Data Science · Summarized by HeadlinesBriefing