GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
ICML 2024

Executable Code Actions Elicit Better LLM Agents

Let an agent act by writing Python instead of one JSON tool call at a time. On multi-tool tasks the best model solved 74% against 52% with JSON; on single calls JSON was as good or better.

Breakdown by FDE Interviews · 13 min read · Updated

About the original · 2024
AUTHORS
Wang, Chen, Yuan, Zhang, Li, Peng, Ji
FROM
University of Illinois Urbana-Champaign, Apple
PUBLISHED
Feb 2024 · ICML 2024
CITED BY
721Semantic Scholar · Oct 2026
IN THIS BREAKDOWN · 10 SECTIONS

You can read 18% of this breakdown.

01

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.

THE IDEA, VISUALLY
SAME TASK, TWO ACTION FORMATS “find the cheapest of these 4 products, in EUR” JSON: ONE TOOL CALL PER TURN price(A) price(B) price(C) price(D) convert answer 6 turns; every turn re-reads all earlier calls and results CODEACT: ONE PROGRAM prices = {p: price(p) for p in ["A", "B", "C", "D"]} best = min(prices, key=prices.get) print(best, convert(prices[best], "USD", "EUR")) 2 turns; loops, variables and errors handled in code Errors come back as Python tracebacks the model can read and fix in its next action, the same feedback a programmer gets. Running model-written code needs a sandbox. Illustrative example; tool names are placeholders. MULTI-TOOL TASKS: CODE WINS FOR MOST M3ToolEval success %, 82 tasks (Table 3) GPT-4 1106 74.4 52.4 53.7 GPT-4 0613 67.1 56.1 45.1 Claude 2 54.9 39.0 29.3 GPT-3.5 0613 51.2 26.8 20.7 Claude Instant 20.7 31.7 24.4 code JSON text On single API calls JSON scored higher for GPT-4 (82.7 vs 76.7).
A code action can loop over items, keep results in variables and read Python errors, so a task that takes six JSON turns can take one program. The advantage showed up on multi-tool tasks, not on single API calls.
Research notes: the problem, approach and results
74.4% vs 52.4%

GPT-4 1106 success on 82 multi-tool tasks with code actions versus JSON

12 of 17

models that scored best with code actions on the multi-tool benchmark

7,139

multi-turn code-action trajectories in the CodeActInstruct fine-tuning set

THE PROBLEM

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.

THE IDEA

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.

THE RESULT

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.

02

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.

THE FULL BREAKDOWN

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

Get Premium · ₹2,000 / $25
  • ◇1 architecture diagram
  • </>1 runnable code experiment
  • ▦3 results tables
  • ?5 interview questions with answers
  1. 03Key takeaways

    The four advantages, both benchmarks, the fine-tuning data, and the misreadings to avoid

    Free account
  2. 04How it works

    The interaction loop, the benchmarks, the training data and how CodeActAgent was evaluated

    Premium
  3. 05The numbers that matter

    The benchmark results in full context, CodeActAgent, and what the margins mean

    Premium
  4. 06Try it yourself

    Read the format results model by model, then price one-call-per-turn against one program

    Premium
  5. 07Where it breaks

    The limits of code actions and of this evaluation

    Premium
  6. 08Using it on a deployment

    Adding a code interpreter to a customer's agent safely and usefully

    Premium
  7. 09Interview angles

    Five questions this paper prepares you for, with answer hints

    Premium
Back to the paper library →