Today we're sharing research that bridges two powerful paradigms in AI agent design: the expressiveness of code-based actions and the reliability of structured generation. Our findings show that forcing CodeAgents to generate both thoughts and code in a structured JSON format can significantly outperform traditional approaches across multiple benchmarks. Traditional JSON Agent : Agents generate structured JSON to call tools. However, parsing code from markdown can be error-prone which leads us to a proposition: why not use structured generation to generate code actions?
Today we're sharing research that bridges two powerful paradigms in AI agent design: the expressiveness of code-based actions and the reliability of structured generation. Our findings show that forcing CodeAgents to generate both thoughts and code in a structured JSON format can significantly outperform traditional approaches across multiple benchmarks.
Figure 1: Accuracy comparison of three approaches: Structured CodeAgent (blue), CodeAgent (orange), and ToolCallingAgent (gray) on SmolBench (GAIA, MATH, SimpleQA, and Frames) . Error bars represent 95% Confidence Intervals.
AI agents need to take actions in the world - whether that's calling APIs, processing data, or reasoning through complex problems. How agents express these actions has evolved through several paradigms:
These agents operate by selecting from a list of predefined tools and generating JSON-formatted calls. This method for calling tools has been popularized by OpenAI's function calling API , and has since then been the most widely used method to call tools.
Code Agents : Agents make use of their innate coding ability and write executable Python code directly.
This shift, first presented as CodeAct in the paper “ Executable Code Actions Elicit Better LLM Agents ” gave AI agents the flexibility to write arbitrary executable Python code in addition to tool-calling.
CodeAgents + Structure: A Better Way to Execute Actions. Covered by Hugging Face on May 28, 2025.