Executable Code Actions Elicit Better LLM Agents

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

arXiv:2402.01030 · 2026-07-27 공개 · arXiv · PDF

llm-agents instruction-tuning mistral llama2 api-bank agent-oriented-tasks code-act python-interpreter

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.

한국어 요약

한 줄 요약

CodeAct는 LLM 에이전트가 실행 가능한 Python 코드를 생성하여 행동을 통합하고, 20% 높은 성공률을 달성하는 새로운 프레임워크이다.

핵심 기여도

핵심 아이디어

기존 LLM 에이전트는 JSON 또는 텍스트 형식으로 행동을 생성하지만, 이는 행동 공간이 제한적이고 유연성이 부족한 문제가 있었다. CodeAct는 실행 가능한 Python 코드를 사용하여 행동을 생성함으로써, LLM이 기존 라이브러리와 동적으로 상호작용할 수 있도록 한다. 이는 데이터 흐름과 제어 흐름을 활용하여 여러 도구를 조합하고 반복 처리를 가능하게 한다. 예를 들어, for-loop이나 if-else 문을 사용하여 여러 입력에 대해 동일한 도구 시퀀스를 적용할 수 있다. CodeAct는 LLM이 사전 학습된 프로그래밍 지식을 활용하여 복잡한 작업을 처리할 수 있도록 지원하며, 이는 기존 텍스트 기반 접근법보다 유연하고 확장 가능한 솔루션이다.

기술적 접근법

주요 결과

의의 및 한계

CodeAct는 LLM 에이전트의 행동 공간을 확장하고 유연성을 높이는 데 기여하며, 복잡한 작업 처리 능력을 향상시킨다. 특히, 기존 도구에 의존하지 않고 파이썬 라이브러리를 활용할 수 있어, 다양한 분야에서 활용 가능하다. 그러나 CodeAct는 파이썬 인터프리터와의 통합이 필수적이므로, 파이썬 기반 환경에서만 사용 가능하다는 한계가 있다. 또한, 코드 생성 능력이 뛰어난 LLM이 필요하므로, 모든 모델이 동일한 성능을 보장하지는 않는다.

실용적 활용

CodeAct는 로봇 제어, 소프트웨어 테스트, 데이터 분석 등 복잡한 작업이 필요한 산업 및 연구 분야에서 활용 가능하다. 특히, CodeActAgent는 모델 학습, 시각화, 자동 디버깅 등 고급 작업을 수행할 수 있어, 연구자와 개발자에게 유용한 도구가 될 수 있다.