If LLM Is the Wizard, Then Code Is the Wand: A Survey on How Code Empowers Large Language Models to Serve as Intelligent Agents

Ke Yang, Jiateng Liu, John Wu, Chaoqi Yang, Yi R. Fung, Sha Li, Zixuan Huang, Xu Cao, Xingyao Wang, Yiquan Wang, Heng Ji, Chengxiang Zhai

TL;DR

This survey argues that training Large Language Models (LLMs) on code is the "secret sauce" that transforms them from simple text generators into autonomous Intelligent Agents (IAs). By leveraging the logical structure and executability of code, LLMs unlock advanced reasoning, gain a universal interface for tool use, and establish a deterministic feedback loop for self-improvement.

What Problem Does This Paper Address?

While traditional LLMs excel at natural language tasks like summarization, they often stumble when faced with complex multi-step reasoning, precise planning, or interacting with external environments. The core challenge is moving from a "chatbot" to an "agent"—a system that can perceive a goal, plan a sequence of actions, execute them using tools, and learn from the results.

The authors posit that code (formal language) provides the necessary scaffolding for these agentic capabilities. Unlike the ambiguity of natural language, code is explicit, modular, and machine-executable. This paper surveys the landscape of "Code-LLMs" to explain why and how code training serves as a catalyst for the emergence of intelligent agents.

Figure 1: An illustration of how code empowers large language models (LLMs) and enhances their downstream applications as intelligent agents (IAs). While traditional LLMs excel in conventional natural language tasks like document classification and question answering, further pre-training or fine-tuning LLMs with human-interpretable and machine-executable code serves as an additional power-up — akin to equipping wizards with mana-boosting wands. This significantly boosts their performance as IAs through intricately woven operational steps.

Methods

The paper provides a comprehensive taxonomy of the literature, categorizing the benefits of code into three main pillars:

  1. Boosting Performance: How code pre-training enhances programming skills, complex reasoning (through Chain-of-Thought and Program-of-Thought), and the ability to capture structured knowledge (like HTML or knowledge graphs).
  2. Connecting to Functional Ends: The "code-centric paradigm" where LLMs use code as a unified, unambiguous language to call external tools, APIs, and even physical robotic controllers.
  3. Executable Environments for Feedback: How placing an LLM inside a code execution environment allows it to receive automated, faithful feedback (e.g., error messages or unit test results) to self-correct without human intervention.
Figure 2: The organization of our paper, with a curated list of the most representative works. The complete work list is provided in Appendix D.

Datasets

The survey references a vast array of datasets and benchmarks used to train and evaluate these capabilities:

  • Programming: AlphaCode, SantaCoder, PolyCoder, and the seminal OpenAI Codex.
  • Reasoning & Math: GSM8k (math word problems), StrategyQA, and LILA.
  • Structured Knowledge: COCOGEN (commonsense graphs), ViStruct (visual structures), and WebGUM (web navigation).
  • Agent Benchmarks: AgentBench, Voyager (Minecraft), and Mind2Web.
  • Evaluation Metrics: CodeBLEU and CodeXGLUE for measuring logical and functional correctness.

Key Insights and Ideas

  • Reasoning is "Unlocked" by Code: Code training significantly boosts Chain-of-Thought (CoT) performance. For example, code-pretrained models show dramatic accuracy jumps in mathematical tasks compared to their text-only counterparts.
  • Program-of-Thought (PoT) > Chain-of-Thought: Instead of just thinking in text, agents that generate code to solve problems (PoT) are more reliable. They offload computation to a Python interpreter, avoiding the "hallucinated math" common in pure text models.
  • Code as a Universal Interface: Code serves as a "wand" that connects the LLM "wizard" to the world. Whether it's a calculator, a web browser, or a robotic arm, code provides a precise, modular way to trigger actions.
  • The Self-Correction Loop: Because code execution is deterministic, it provides "free" feedback. If a generated plan fails, the error message serves as a prompt for the model to "debug" its own reasoning.
Figure 3: How code pre-training boosts LLMs’ performance.

Key Results

  • Quantitative Reasoning Jumps: The authors highlight that GPT-3 versions trained on code (e.g., text-davinci-002) improved GSM8k accuracy from ~15% to ~47% compared to non-code versions.
  • Agentic Success: In complex environments like Minecraft, agents like Voyager use code to store "learned skills" in a library, allowing them to solve increasingly difficult tasks by recombining previously written code snippets.
  • Tool Integration: The "code-centric paradigm" (e.g., Toolformer, Gorilla) allows LLMs to dynamically generate API calls, enabling them to handle thousands of different tools with high precision.
Figure 4: The code-centric tool-calling paradigm serves as a unified interface between LLMs and a large variety of functional ends, thus enabling many cross-modality and cross-domain tasks.

Limitations and Future Work

  • Causality Gap: While we know code training helps reasoning, the exact "why" remains elusive. Identifying which specific properties of code (e.g., recursion, logic gates) are most responsible is an open research question.
  • Beyond Code: Are there other data modalities that could provide similar reasoning boosts?
  • Learning from Multi-turn Feedback: While execution feedback is powerful, current methods (like simple prompting) are often inefficient. The authors suggest that Reinforcement Learning (RL) with well-designed reward functions derived from code execution is a promising but difficult future path.
  • Complex Tool Invocation: Learning to use highly specialized, domain-specific libraries (e.g., for chemistry or biology) remains a challenge for general-purpose agents.
The automated feedback loop where code execution provides critics and comments for model self-improvement.

Summary updated

BibTeX
@misc{yang2024if,
  author = {Ke Yang and Jiateng Liu and John Wu and Chaoqi Yang and Yi R. Fung and Sha Li and Zixuan Huang and Xu Cao and Xingyao Wang and Yiquan Wang and Heng Ji and Chengxiang Zhai},
  title = {{If LLM Is the Wizard, Then Code Is the Wand: A Survey on How Code Empowers Large Language Models to Serve as Intelligent Agents}},
  year = {2024},
  eprint = {2401.00812},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2401.00812},
}
Figure