Lemur: Harmonizing Natural Language and Code for Language Agents

Yiheng Xu, Hongjin Su, Chen Xing, Boyu Mi, Qian Liu, Weijia Shi, Binyuan Hui, Fan Zhou, Yitao Liu, Tianbao Xie, Zhoujun Cheng, Siheng Zhao, Lingpeng Kong, Bailin Wang, Caiming Xiong, Tao Yu

The AI community is rapidly shifting its focus from conversational "chatbots" to "functional agents"—models capable of sensing their environment, formulating plans, and taking concrete actions. To operate effectively, these agents require a delicate balance of two distinct skills: natural language (NL) proficiency for human interaction and reasoning, and coding capabilities to execute actions in the real world (e.g., calling APIs, querying databases, or navigating web browsers).

Currently, open-source Large Language Models (LLMs) often fall into a "specialization trap." Models like Llama-2 excel at natural language but struggle with complex coding tasks, whereas models like CodeLlama are coding powerhouses that lose some general reasoning nuances. To bridge this gap, researchers have introduced Lemur, a new family of open-source 70B parameter models designed to harmonize natural language reasoning with code-based execution.

The Two-Stage Training Pipeline

To create a versatile agent backbone, the researchers developed a two-stage training pipeline starting from the Llama-2-70B base model.

The Lemur training pipeline involves code-centric pre-training followed by supervised fine-tuning.
  1. Code-Centric Continued Pre-training: The base model underwent continued training on a massive 90-billion-token corpus. Crucially, the team employed a 10:1 code-to-text ratio. Ablation studies revealed this ratio is the "sweet spot" for aggressively boosting coding proficiency while retaining enough natural language context to prevent catastrophic forgetting of reasoning abilities. The code data heavily favored interpreted languages like Python, SQL, and Bash, which serve as the primary "languages of action" for agents.
  2. Instruction Fine-Tuning: To produce the final Lemur-Chat model, the system was fine-tuned on 300,000 diverse examples. This dataset blended human-written dialogues (OpenAssistant), reasoning-heavy tasks (OpenOrca), real-world user prompts (ShareGPT), and complex coding instructions (Evol-CodeAlpaca).

Evaluating Agent Capabilities

The authors evaluated Lemur across a comprehensive battery of benchmarks, including 8 fundamental capability tests (like MMLU and HumanEval) and 13 agent-specific benchmarks. These agent tasks were categorized into four core skills: augmenting with tools, self-debugging, exploring environments, and following feedback.

Lemur agents are trained to understand complex feedback and convert it into executable symbolic sequences.

A central insight from the paper is that code is not just for software engineers; it represents the action space for agents. A model that cannot write a valid API call cannot effectively "act." Furthermore, experiments in web browsing environments (WebArena) demonstrated that mapping an agent's action space to Python representations (e.g., type(id, content)) yielded better performance than predicting raw text commands. Leveraging a model's internal "code logic" makes it a more reliable planner.

Key Results

By harmonizing these domains, Lemur significantly narrows the performance gap with proprietary models like GPT-3.5-turbo and GPT-4.

  • Balanced Excellence: Lemur-70B achieved an average score of 47.9 across fundamental text and code benchmarks, surpassing both Llama-2-70B (43.6) and CodeLlama-34B (46.0).
  • Superior Agent Performance: Lemur-Chat outperformed other open-source models in 12 out of 13 agent benchmarks.
  • Tool Usage: On tool-augmented math tasks (M-GSM8K), Lemur-Chat scored 58.33%, nearly doubling the performance of Llama-2-70B-Chat (33.33%).
  • Environment Interaction: In the ALFWorld physical simulation, Lemur-Chat scored 59.70, vastly outperforming CodeLlama-34B-Instruct (37.31%) and Llama-2-70B-Chat (21.64%).

Limitations and Future Work

While Lemur represents a significant leap for open-source agents, GPT-4 still maintains a lead in complex reasoning and long-horizon planning within partially observable environments. Additionally, the model struggled with highly domain-specific knowledge in cybersecurity tasks (CTF), indicating that general harmonization is just the first step toward specialized expert agents. Finally, the computational constraints of training 70B parameter models made exhaustive searches for the perfect data mixture ratio difficult, pointing toward future research into optimizing data mixtures and achieving similar harmonization in smaller, more efficient models.

Summary updated

BibTeX
@inproceedings{xu2024lemur,
  author = {Yiheng Xu and Hongjin SU and Chen Xing and Boyu Mi and Qian Liu and Weijia Shi and Binyuan Hui and Fan Zhou and Yitao Liu and Tianbao Xie and Zhoujun Cheng and Siheng Zhao and Lingpeng Kong and Bailin Wang and Caiming Xiong and Tao Yu},
  title = {{Lemur: Harmonizing Natural Language and Code for Language Agents}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=hNhwSmtXRh},
}
Figure