NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

AgentCoder: Multi-Agent-based Code Generation with Iterative Testing and Optimisation

Dong Huang, Qingwen Bu, Jie M. Zhang, Michael Luck, Heming CuiarXiv 2023 · DOI

Introduction

Large Language Models (LLMs) like GPT-4 have demonstrated remarkable capabilities in code generation. However, they frequently suffer from "hallucinations" and subtle logic errors. Traditional self-refinement techniques often fall short because the same model responsible for generating the code is also tasked with identifying its flaws, leading to confirmation bias. While existing multi-agent frameworks like MetaGPT or ChatDev attempt to simulate software development teams, they often struggle with inefficient feedback loops and high token overhead.

AgentCoder addresses these challenges by introducing a specialized multi-agent framework that decouples the roles of code generation and testing. By utilizing independent agents for programming and test design, AgentCoder achieves state-of-the-art performance with significantly reduced computational costs.

Methodology: The Three-Agent Architecture

AgentCoder employs a lean, three-agent architecture designed to maximize testing rigor while minimizing conversational turns.

The AgentCoder multi-agent architecture, featuring specialized Programmer, Test Designer, and Test Executor agents.
  1. The Programmer Agent: This agent is responsible for generating the initial code and subsequent refinements. It follows a Chain-of-Thought (CoT) process, breaking down the problem into requirement analysis, algorithm selection, and pseudocode before producing the final Python implementation.
  2. The Test Designer Agent: To avoid confirmation bias, this agent generates test cases independently of the Programmer Agent. It operates "blind," seeing only the requirements and not the generated code. It is specifically prompted to create a comprehensive suite of tests, including basic functionality, edge cases (e.g., empty inputs, boundary conditions), and large-scale performance tests.
  3. The Test Executor Agent: Unlike the other two, this is a non-LLM component—a Python script that executes the code against the designed tests in a local, sandboxed environment. It captures real-world feedback, such as tracebacks and assertion errors, which are then fed back to the Programmer Agent for iterative optimization.

Experimental Setup

The framework was evaluated on four major benchmarks: HumanEval, MBPP, and their "Enhanced Test" counterparts, HumanEval-ET and MBPP-ET. These ET datasets are particularly challenging as they include significantly more test cases to expose subtle bugs. The authors tested AgentCoder across 14 different LLMs, including GPT-4, GPT-3.5, Llama3, and StarCoder, to demonstrate its broad applicability.

Key Results and Performance

AgentCoder sets a new state-of-the-art (SOTA) for code generation across multiple benchmarks.

Performance comparison of AgentCoder against zero-shot LLMs and various optimization methods on HumanEval and MBPP benchmarks.
  • State-of-the-Art Accuracy: Using GPT-4 as the backbone, AgentCoder achieved a 96.3% pass@1 on HumanEval and 91.8% on MBPP, outperforming previous leaders like MetaGPT and Reflexion.
  • Exceptional Token Efficiency: AgentCoder is remarkably lean. On HumanEval, it consumed only 56.9K tokens, a 60-70% reduction compared to MetaGPT (138.2K) and ChatDev (183.7K), while delivering superior results.
  • Robustness on Enhanced Benchmarks: The framework's strength is most evident on the ET datasets. For instance, on MBPP-ET, AgentCoder (GPT-4) achieved 91.8%, significantly higher than zero-shot GPT-4 (52.2%).
  • Model Agnostic Gains: The framework consistently improved the performance of all underlying models. For example, it more than doubled the performance of Claude-instant-1 on several benchmarks.

Discussion and Insights

The success of AgentCoder highlights several critical insights for the future of AI-assisted programming:

  • Independence is Key: Decoupling test generation from code generation is vital for overcoming the confirmation bias inherent in single-agent or tightly coupled multi-agent systems.
  • Specialization over Scale: AgentCoder demonstrates that a small team of highly specialized agents can outperform larger, more complex "social" simulations. This leads to better performance with lower latency and cost.
  • The Importance of Rigorous Testing: The significant performance gap between AgentCoder and other methods on the ET datasets underscores that high-quality, independent testing is the primary bottleneck in automated code generation.

Conclusion

AgentCoder provides a highly efficient and effective framework for multi-agent code generation. By prioritizing independent test design and iterative refinement based on real-world execution feedback, it achieves SOTA results while remaining significantly more token-efficient than its predecessors. Future work may involve extending the framework to other programming languages and enhancing the safety of the local execution environment.

Summary updated

BibTeX
@misc{huang2023agentcoder,
  author = {Dong Huang and Qingwen Bu and Jie M. Zhang and Michael Luck and Heming Cui},
  title = {{AgentCoder: Multi-Agent-based Code Generation with Iterative Testing and Optimisation}},
  year = {2023},
  eprint = {2312.13010},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2312.13010},
}
Figure