---
title: "CodeAgents + Structure: A Better Way to Execute Actions"
description: "Forcing code-writing agents to emit their reasoning and Python code as a structured JSON blob (thoughts + code) beats both markdown-parsed CodeAgents and JSON tool-calling agents by 2-7 percentage points on GAIA, MATH, SimpleQA and Frames for capable models."
url: "https://swe.quest/articles/codeagents-structure-a-better-way-to-execute-actions-5f9ad7c5f62e107c"
canonical: "https://huggingface.co/blog/structured-codeagent"
source: "Hugging Face"
published: "2025-05-28"
difficulty: "medium"
kind: "Research"
reading_minutes: 8
tags: ["ai-agents","llms","evals","python"]
---

# CodeAgents + Structure: A Better Way to Execute Actions

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-05-28, 8 min read, Research. Original: [https://huggingface.co/blog/structured-codeagent](https://huggingface.co/blog/structured-codeagent)

## Summary

Forcing code-writing agents to emit their reasoning and Python code as a structured JSON blob (thoughts + code) beats both markdown-parsed CodeAgents and JSON tool-calling agents by 2-7 percentage points on GAIA, MATH, SimpleQA and Frames for capable models. An analysis of 15,724 traces shows first-step parsing errors cut success from 51.3% to 42.3% and raise average steps from 3.18 to 4.63, which structured generation eliminates. Smaller models such as Mistral-7B pay a "structure tax", producing broken Python when juggling JSON escaping and code at once, so the approach is recommended for 32B+ or frontier models. In smolagents it is enabled with use\_structured\_outputs\_internally=True.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [AI agents](https://swe.quest/tags/ai-agents.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Evaluation](https://swe.quest/tags/evals.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- LLM tool calling ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- structured outputs / JSON mode
- Python ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))

## Keywords

smolagents, CodeAgent, CodeAct, GAIA, structured generation, Hugging Face

## Related posts

- [Our Transformers Code Agent beats the GAIA benchmark 🏅](https://swe.quest/articles/our-transformers-code-agent-beats-the-gaia-benchmark-6fa8664c9f76e83d.md): Hugging Face · 2024-07-01 · Medium · 12 min read · AI agents, Evaluation, LLMs, Sandboxing & isolation
  A ReactCodeAgent built with Transformers Agents and GPT-4o scored 44.2% on the GAIA validation set, ranking first, and 33.3% on the test set, ranking second overall with the best Level 3 score.
- [Introducing smolagents: simple agents that write actions in code.](https://swe.quest/articles/introducing-smolagents-simple-agents-that-write-actions-in-code-081cf3257f37300e.md): Hugging Face · 2024-12-31 · Medium · 11 min read · AI agents, LLMs, Python, Open source
  smolagents is a minimal Python library from Hugging Face for building LLM agents, with first-class support for code agents that write their actions as Python code instead of JSON tool calls.
- [CoderForge-Preview: SOTA open dataset for training efficient coding agents](https://swe.quest/articles/coderforge-preview-sota-open-dataset-for-training-efficient-coding-agents-83e1f3c7a7bdb67a.md): Together AI · 2026-02-25 · Hard · 14 min read · Model training, AI for coding, AI agents, Evaluation, LLMs
  CoderForge-Preview is an open dataset of 258K test-verified coding agent trajectories (155K passing) covering 51K tasks across 1,655 repositories from R2E-Gym, SWE-Smith and SWE-Rebench.
- [The Multi-Model Playbook](https://swe.quest/articles/the-multi-model-playbook-1f23a70284b23c2b.md): Benchling Engineering · 2026-01-16 · Medium · 7 min read · LLMs, AI agents, AI for coding, System design
  Production LLM agents that run across multiple providers (Claude, GPT, Gemini, Llama, Nova) work best when tasks are decomposed into either small complex subtasks or large simple ones.
- [Open-source DeepResearch – Freeing our search agents](https://swe.quest/articles/open-source-deepresearch-freeing-our-search-agents-72a8cc1624888c05.md): Hugging Face · 2025-02-04 · Medium · 17 min read · AI agents, LLMs, Evaluation, Open source
  Hugging Face reproduced OpenAI's Deep Research agent in about 24 hours using the open smolagents framework and reached 55.15% on the GAIA validation set, up from roughly 46% for the previous open state of the art (Magentic-One).

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
