Skip to main content
QUICK REVIEW

[Paper Review] AgentCoder: Multi-Agent-based Code Generation with Iterative Testing and Optimisation

Dong Huang, Jie M. Zhang|arXiv (Cornell University)|Dec 20, 2023
Software Engineering ResearchComputer Science16 citations
TL;DR

AgentCoder introduces a three-agent framework (programmer, test designer, test executor) to iteratively generate code and tests, run them locally, and refine based on execution feedback, outperforming single-agent and baseline methods across multiple datasets and LLMs.

ABSTRACT

The advancement of natural language processing (NLP) has been significantly boosted by the development of transformer-based large language models (LLMs). These models have revolutionized NLP tasks, particularly in code generation, aiding developers in creating software with enhanced efficiency. Despite their advancements, challenges in balancing code snippet generation with effective test case generation and execution persist. To address these issues, this paper introduces Multi-Agent Assistant Code Generation (AgentCoder), a novel solution comprising a multi-agent framework with specialized agents: the programmer agent, the test designer agent, and the test executor agent. During the coding procedure, the programmer agent will focus on the code generation and refinement based on the test executor agent's feedback. The test designer agent will generate test cases for the generated code, and the test executor agent will run the code with the test cases and write the feedback to the programmer. This collaborative system ensures robust code generation, surpassing the limitations of single-agent models and traditional methodologies. Our extensive experiments on 9 code generation models and 12 enhancement approaches showcase AgentCoder's superior performance over existing code generation models and prompt engineering techniques across various benchmarks. For example, AgentCoder (GPT-4) achieves 96.3\% and 91.8\% pass@1 in HumanEval and MBPP datasets with an overall token overhead of 56.9K and 66.3K, while state-of-the-art obtains only 90.2\% and 78.9\% pass@1 with an overall token overhead of 138.2K and 206.5K.

Motivation & Objective

  • Motivate the need for robust code generation that jointly optimizes code and test quality.
  • Propose a multi-agent architecture to separate concerns among code creation, test design, and execution.
  • Demonstrate that agent collaboration yields higher code correctness and test coverage than single-agent setups.

Proposed method

  • Three specialised agents operate in sequence: programmer agent for code generation, test designer agent for diverse test case creation, and test executor agent for local execution and feedback.
  • Programmer agent uses a Chain-of-Thought prompt to simulate step-by-step programming: understanding, algorithm choice, pseudocode, and implementation.
  • Test designer agent is prompted to create basic, edge, and large-scale tests to probe correctness and performance.
  • Test executor agent runs code with the designer’s tests in a local environment and returns runtime and assertion feedback to drive refinement.
  • Iterative loop continues until all tests pass or the budget is exhausted.
  • Evaluation spans 12 LLMs and 13 optimization approaches on four datasets (HumanEval, MBPP and their enhanced versions).
Figure 1: Pipeline of AgentCoder with a code generation example from HumanEval
Figure 1: Pipeline of AgentCoder with a code generation example from HumanEval

Experimental results

Research questions

  • RQ1RQ1: How does AgentCoder perform compared with base LLMs and baselines?
  • RQ2RQ2: How do the three agents contribute to effectiveness?
  • RQ3RQ3: How do code refinement iterations affect performance?
  • RQ4RQ4: How accurate are the tests generated by the test designer agent?
  • RQ5RQ5: How adequate are the tests in terms of code coverage?
  • RQ6RQ6: Should programmer and test designer roles be separated across different agents?

Key findings

  • AgentCoder consistently outperforms base LLMs and optimisation baselines across all datasets and models.
  • With GPT-4, AgentCoder achieves an average pass@1 of 91.5% across datasets (vs 59.7% for GPT-4 alone).
  • AgentCoder substantially improves GPT-3.5-turbo: 79.9% pass@1 on HumanEval and MBPP, vs 57.3% for GPT-3.5-turbo alone.
  • The test designer agent yields highly accurate test cases (87.8% on HumanEval, 89.9% on MBPP) and high code coverage (84.7–87.5% first-five tests).
  • A single-agent setup underperforms compared to the multi-agent design in pass@1, test accuracy, and test coverage.
  • Ablations show separate code generation and test design roles yield substantial performance gains over unified single-agent configurations.
Figure 2: A case illustration of CodeCoT and AgentCoder generated code for HumanEval task. CodeCoT ignores to use of abs() function to check further the absolute values are lower than the threshold, while AgentCoder employs it to handle the negative values.
Figure 2: A case illustration of CodeCoT and AgentCoder generated code for HumanEval task. CodeCoT ignores to use of abs() function to check further the absolute values are lower than the threshold, while AgentCoder employs it to handle the negative values.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.