HackerPapers

arXiv:2402.01030cs.CL

Executable Code Actions Elicit Better LLM Agents

Xingyao Wang, Yangyi Chen, Lifan Yuan, Yizhe Zhang, Yunzhu Li, Hao Peng, Heng Ji

Abstract

Large Language Model (LLM) agents, capable of performing a broad range of actions, such as invoking tools and controlling robots, show great potential in tackling real-world challenges. LLM agents are typically prompted to produce actions by generating JSON or text in a pre-defined format, which is usually limited by constrained action space (e.g., the scope of pre-defined tools) and restricted flexibility (e.g., inability to compose multiple tools). This work proposes to use executable Python code to consolidate LLM agents' actions into a unified action space (CodeAct). Integrated with a Python interpreter, CodeAct can execute code actions and dynamically revise prior actions or emit new actions upon new observations through multi-turn interactions. Our extensive analysis of 17 LLMs on API-Bank and a newly curated benchmark shows that CodeAct outperforms widely used alternatives (up to 20% higher success rate). The encouraging performance of CodeAct motivates us to build an open-source LLM agent that interacts with environments by executing interpretable code and collaborates with users using natural language. To this end, we collect an instruction-tuning dataset CodeActInstruct that consists of 7k multi-turn interactions using CodeAct. We show that it can be used with existing data to improve models in agent-oriented tasks without compromising their general capability. CodeActAgent, finetuned from Llama2 and Mistral, is integrated with Python interpreter and uniquely tailored to perform sophisticated tasks (e.g., model training) using existing libraries and autonomously self-debug.

arXiv comments
Accepted by ICML 2024; Code, data, model, and demo are available at https://github.com/xingyaoww/code-act
Journal reference
DOI
Subjects
cs.CLComputation and Language cs.AIArtificial Intelligence

On Hacker News

Linked by 7 identifiable commenters in 7 comments across 5 threads, from Jul 2025 to Sep 2026. Found in 3 HN submissions from May 2024 to Dec 2025. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments5 threads

    • The idea to use python code instead of other kinds of tool calls is taken from smolagents: https://huggingface.co/blog/smolagents It is based on this paper https://huggingface.co/papers/2402.01030 and calls this idea CodeAct. The paper is actually from Apple…

      amaiView on HNParent context

    • This is called CodeAct (https://arxiv.org/abs/2402.01030) and is available in a number of frameworks. Patent was applied for 04.03.2026. langgraph-codeact _shipped_ this capability in February.

      anankaieView on HNParent context

    • Isn't that patent similar to CodeAct [1], originally described in this paper [2]? [1] https://learn.microsoft.com/en-us/agent-framework/agents/cod... [2] https://arxiv.org/abs/2402.01030

      rippeltippelView on HNParent context

    • The "invention" was first published in 2024, by Chinese researchers: https://arxiv.org/abs/2402.01030 Beyond that, it's a trivial batching pattern. Any remotely competent systems engineer developing an agent would immediately reach for it, it's the most basic tool in the toolbox…

      ux266478View on HNParent context

  1. Anthropic acquires Bun 1 comment
    • Interesting. Looking through a strategic lens, I feel like this is related to the $1,000 free credit for Claude Code Web (I used a few hundred). What the heck are they aiming for? CodeAct? (https://arxiv.org/abs/2402.01030)

      threecheeseView on HNParent context

    • This is insane! We've been training models to write and edit code, and now this? These guys should read this (CodeAct) paper https://arxiv.org/abs/2402.01030 > LLM agents are typically prompted to produce actions by generating JSON or text in a pre-defined format, which is…

      tucnakView on HNParent context

  2. Tools: Code Is All You Need 1 comment
    • This is similar to the tool call (fixed code & dynamic params) vs code generation (dynamic code & dynamic params) discussion: tools offer contrains and save tokens, code gives you flexibility. Some papers suggest that generating code is often superior and this will likely become…

      elyaseView on HNParent context

Submitted to Hacker News

  • Show HN: Gemini 2 with unrestricted code execution

    I recently experimented using Gemini 2 Flash and Gemini 2 Flash Thinking with unrestricted code execution in a local sandbox and open sourced the results: https://github.com/gradion-ai/freeact. Here's an example that uses Gemini 2 Flash Thinking as agent that acts via code, executed in a sandbox based on IPython and Docker: https://gist.github.com/krasserm/dcdae47f85ee9922e3284953d07... Gemini's code execution environment is restricted to selected Python libraries like NumPy or SymPy and…

  • Show HN: Construct – API-first coding assistant with CodeAct tool calling

    Construct is an open-source AI coding assistant that runs as a gRPC service rather than just a CLI tool. You can run it locally on your laptop or on a remote box, connect multiple clients, disconnect and reconnect without losing context, and integrate it into other tools easily. I wanted something I could leave running and come back to and that is easy to run in a sandbox. Instead of JSON schema, agents write JavaScript to interact with tools. That means they have access to loops, conditionals…

  • Executable Code Actions Elicit Better LLM Agents

Connected through shared HN threads, not inferred similarity or a recommendation.