---
title: code-act
canonical_url: "https://www.modelscope.cn/datasets/thomas/code-act"
md_url: "https://www.modelscope.cn/datasets/thomas/code-act.md"
repository: thomas/code-act
last_updated: 2024-10-17
license: apache-2.0
storage_size: "117 MB"
domain:
  - configs
  - size_categories
  - dataset_info
  - language
  - task_categories
tasks:
  - "{config_name=default, data_files=[{split=codeact, path=data/codeact-*}, {split=general, path=data/general-*}]}"
  - "1K<n<10K"
  - dataset_size
  - en
  - text-generation
downloads: 356
stars: 1
---

# code-act

> code-act - thomas 在 ModelScope 开源的数据集。Executable Code Actions Elicit Better LLM Agents

thomas/code-act 是 ModelScope 魔搭社区上的{config_name=default, data_files=[{split=codeact, path=data/codeact-*}, {split=general, path=data/general-*}]}、1K<n<10K、dataset_size数据集，涉及 configs、size_categories、dataset_info 领域，存储大小 117 MB，采用 apache-2.0 许可。

- **Repository**: thomas/code-act
- **License**: apache-2.0
- **Tasks**: {config_name=default, data_files=[{split=codeact, path=data/codeact-*}, {split=general, path=data/general-*}]}, 1K<n<10K, dataset_size, en, text-generation
- **Domain**: configs, size_categories, dataset_info, language, task_categories
- **Storage size**: 117 MB
- **Downloads**: 356
- **Stars**: 1
- **Last updated**: 2024-10-17

Source: https://www.modelscope.cn/datasets/thomas/code-act

---

<h1 align="center"> Executable Code Actions Elicit Better LLM Agents </h1>

<p align="center">
<a href="https://github.com/xingyaoww/code-act">💻 Code</a>
•
<a href="https://arxiv.org/abs/2402.01030">📃 Paper</a>
•
<a href="https://huggingface.co/datasets/xingyaoww/code-act" >🤗 Data (CodeActInstruct)</a>
•
<a href="https://huggingface.co/xingyaoww/CodeActAgent-Mistral-7b-v0.1" >🤗 Model (CodeActAgent-Mistral-7b-v0.1)</a>
•
<a href="https://chat.xwang.dev/">🤖 Chat with CodeActAgent!</a>
</p>

We propose to use executable Python **code** to consolidate LLM agents’ **act**ions 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 (e.g., code execution results) through multi-turn interactions.

![Overview](https://github.com/xingyaoww/code-act/blob/main/figures/overview.png?raw=true)

## Why CodeAct?

Our extensive analysis of 17 LLMs on API-Bank and a newly curated benchmark [M<sup>3</sup>ToolEval](docs/EVALUATION.md) shows that CodeAct outperforms widely used alternatives like Text and JSON (up to 20% higher success rate). Please check our paper for more detailed analysis!

![Comparison between CodeAct and Text/JSON](https://github.com/xingyaoww/code-act/blob/main/figures/codeact-comparison-table.png?raw=true)
*Comparison between CodeAct and Text / JSON as action.*

![Comparison between CodeAct and Text/JSON](https://github.com/xingyaoww/code-act/blob/main/figures/codeact-comparison-perf.png?raw=true)
*Quantitative results comparing CodeAct and {Text, JSON} on M<sup>3</sup>ToolEval.*



## 📁 CodeActInstruct

We collect an instruction-tuning dataset CodeActInstruct that consists of 7k multi-turn interactions using CodeAct. Dataset is release at [huggingface dataset 🤗](https://huggingface.co/datasets/xingyaoww/code-act). Please refer to the paper and [this section](#-data-generation-optional) for details of data collection.


![Data Statistics](https://github.com/xingyaoww/code-act/blob/main/figures/data-stats.png?raw=true)
*Dataset Statistics. Token statistics are computed using Llama-2 tokenizer.*

## 🪄 CodeActAgent

Trained on **CodeActInstruct** and general conversaions, **CodeActAgent** excels at out-of-domain agent tasks compared to open-source models of the same size, while not sacrificing generic performance (e.g., knowledge, dialog). We release two variants of CodeActAgent:
- **CodeActAgent-Mistral-7b-v0.1** (recommended, [model link](https://huggingface.co/xingyaoww/CodeActAgent-Mistral-7b-v0.1)): using Mistral-7b-v0.1 as the base model with 32k context window.
- **CodeActAgent-Llama-7b** ([model link](https://huggingface.co/xingyaoww/CodeActAgent-Llama-2-7b)): using Llama-2-7b as the base model with 4k context window.

![Model Performance](https://github.com/xingyaoww/code-act/blob/main/figures/model-performance.png?raw=true)
*Evaluation results for CodeActAgent. ID and OD stand for in-domain and out-of-domain evaluation correspondingly. Overall averaged performance normalizes the MT-Bench score to be consistent with other tasks and excludes in-domain tasks for fair comparison.*


Please check out [our paper](TODO) and [code](https://github.com/xingyaoww/code-act) for more details about data collection, model training, and evaluation.


## 📚 Citation

```bibtex
@misc{wang2024executable,
      title={Executable Code Actions Elicit Better LLM Agents}, 
      author={Xingyao Wang and Yangyi Chen and Lifan Yuan and Yizhe Zhang and Yunzhu Li and Hao Peng and Heng Ji},
      year={2024},
      eprint={2402.01030},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}
```
