IN THIS BREAKDOWN · 10 SECTIONS
You can read 18% of this breakdown.
The paper in one minute
Most agents act by producing a tool call in a fixed format: a JSON object with a function name and arguments, or a line of text the harness parses. One call per turn, then the result comes back, then the next call. For a task like "find the cheapest of these four products and give the price in euros", that is five or six turns, each one re-reading every earlier call and result. The format also cannot say "do this for each item" or "if the first lookup fails, try the other site".
Xingyao Wang, Heng Ji and colleagues at the University of Illinois with Apple propose CodeAct: let the action be Python code, executed in an interpreter attached to the agent. A single action can loop over items, call several tools, store results in variables, use any library already installed, and print just what the model needs to see. When code fails, the interpreter's traceback comes back as the observation, and the model fixes its code in the next turn, as a programmer would.
The paper has two halves. First, an evaluation of 17 models comparing code, JSON and text actions on two benchmarks: API-Bank, where each action is a single API call, and M3ToolEval, a new set of 82 tasks that need several tools across several turns. Code actions were roughly even on single calls and clearly better on multi-tool tasks for most capable models. Second, CodeActInstruct, about 7,000 multi-turn trajectories, used to fine-tune Llama 2 and Mistral 7B into CodeActAgent, an open model that acts through code.
Research notes: the problem, approach and results
GPT-4 1106 success on 82 multi-tool tasks with code actions versus JSON
models that scored best with code actions on the multi-tool benchmark
multi-turn code-action trajectories in the CodeActInstruct fine-tuning set
Agents usually act by emitting one JSON or text tool call per turn. That cannot express loops, conditions or reuse of intermediate results, so multi-step tasks take many turns and each turn re-reads the growing history.
Make the action a Python program run in an interpreter. The model can compose tools, use any installed library, and read tracebacks to fix itself. Then fine-tune open models on 7k multi-turn trajectories of this behavior.
Across 17 models, code actions matched JSON and text on single API calls and beat them on a new multi-tool benchmark, by up to 20 points with up to 30% fewer actions. A fine-tuned open 7B model improved on agent tasks while keeping its general skills.
Why it matters to an FDE
The action format is one of the first decisions in an agent build, and it is often made by default: whatever the framework does. This paper is the evidence for choosing deliberately.
Use code actions for compositional work. Data analysis, reconciliation across systems, batch operations over many records: anything where the natural plan contains a loop or a condition. That is where code actions won by large margins.
Keep structured calls for single, high-stakes actions. On single API calls, JSON was as good or better for the strongest models. A refund, a record update or a message send is one call with exact arguments; a schema validates it more simply than reviewing code.
Expect cheaper long tasks. Collapsing many turns into one program avoids re-reading a growing history on every step. The paper reports up to 30% fewer actions; for tasks with dozens of tool calls the token difference can be much larger.
Budget for the interpreter as a security boundary. Executing model-written code needs a sandbox: no network unless allowed, limited files, resource limits, and policy checks on the tools the code can call. The paper focuses on capability; deployments must add containment.
Small open models need training for it. Untuned 7B models scored near zero on the multi-tool benchmark. If the customer must run a small model, plan for fine-tuning or use structured calls.
Understand the mechanism. Try it on a real problem.
Unlock this breakdown and 99 more papers.
Premium opens every paper in full, plus every answer, concept, course and guide on the site. One payment for six months of access.
6 months · One payment · No auto-renewal
- ◇1 architecture diagram
- </>1 runnable code experiment
- ▦3 results tables
- ?5 interview questions with answers
- 03Key takeaways
The four advantages, both benchmarks, the fine-tuning data, and the misreadings to avoid
Free account - 04How it works
The interaction loop, the benchmarks, the training data and how CodeActAgent was evaluated
Premium - 05The numbers that matter
The benchmark results in full context, CodeActAgent, and what the margins mean
Premium - 06Try it yourself
Read the format results model by model, then price one-call-per-turn against one program
Premium - 07Where it breaks
The limits of code actions and of this evaluation
Premium - 08Using it on a deployment
Adding a code interpreter to a customer's agent safely and usefully
Premium - 09Interview angles
Five questions this paper prepares you for, with answer hints
Premium - 10Read next
Where to go from here on this site
Premium
