Pydantic Engineer Michael Pfaffenberger: Code Mode Halves Costs on Long Tasks, But Is More Expensive with Just 5 Records
Pydantic engineer Michael Pfaffenberger ran tests scoring 8 models across 5 small applications using 5,276 evaluations. He found that code mode (having the model write programs to call tools) reduced average costs by 58% and time by 51% on long tasks, but increased costs by 21% to 38% when handling just 5 records.
A popular saying among AI Agent developers is that rather than having the model call tools one by one, it is better to have it write a program that wraps tool calls in a loop, making everything cheaper, faster, and more accurate. Pydantic engineer Michael Pfaffenberger believes in this direction, but he noticed that almost all numbers supporting this argument come from complex Agent scenarios with hundreds of tools or massive payloads. In reality, many Agents are quite simple: a few CRUD tools and a specific task. So he designed an intentionally simple benchmark test to verify under what conditions this argument actually holds true.
The test covered five small Pydantic AI applications—shopping cart, calendar, chatroom, kanban board, and inventory system—each with single-record CRUD tools, paginated lists, and no shell, file system, or bulk interfaces. Three workloads were used: 50 daily short tasks (averaging 13 tool calls), 12 long multi-step tasks (60 to 500 records, averaging 68 calls), and one repeatable rule task that could scale from 5 to 200 records. Eight models were tested, with code mode both on and off, resulting in 5,276 scored runs, verified by a deterministic oracle rather than an LLM judge.
The core finding is that the longer the task, the greater the advantage of code mode. On long tasks, the eight models saw an average cost reduction of 58%, a time reduction of 51%, and a success rate increase of 16 percentage points. At a scale of 200 records, code mode was 47% to 75% cheaper than standard tool calling. However, at just 5 records, code mode was 21% to 38% more expensive in three of the five tasks. The crossover point appears to be between 20 and 50 records.