Skip to main content
QUICK 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 Science被引用 16
一句话总结

AgentCoder 引入一个三代理框架(程序员、测试设计师、测试执行者),以迭代生成代码和测试,在本地运行,并基于执行反馈进行 refined,跨多数据集和大语言模型在单代理与基线方法之上表现优越。

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.

研究动机与目标

  • 需要鲁棒的代码生成以同时优化代码与测试质量的动机。
  • 提出一种多代理架构,将代码创作、测试设计与执行的关注点分离。
  • 证明代理协作能比单代理设置带来更高的代码正确性与测试覆盖率。

提出的方法

  • 三个专门化代理按顺序工作:用于代码生成的程序员代理、用于创建多样化测试用例的测试设计师代理,以及用于本地执行与反馈的测试执行者代理。
  • 程序员代理使用思维链提示,进行逐步编程的模拟:理解、算法选择、伪代码与实现。
  • 测试设计师代理被提示创建基础、边界与大规模测试,用于探查正确性与性能。
  • 测试执行者代理在本地环境中运行设计师的测试并返回运行时与断言反馈,以驱动 refinement。
  • 迭代循环持续,直到所有测试通过或预算耗尽。
  • 评估覆盖四个数据集(HumanEval、MBPP及其增强版本)上的四个数据集,在四个数据集上对 12 个 LLMs 和 13 种优化方法进行评估。
Figure 1: Pipeline of AgentCoder with a code generation example from HumanEval
Figure 1: Pipeline of AgentCoder with a code generation example from HumanEval

实验结果

研究问题

  • RQ1RQ1:AgentCoder 相较于基础 LLM 与基线方法的表现如何?
  • RQ2RQ2:三代理如何共同提升效果?
  • RQ3RQ3:代码 refinement 循环对性能有何影响?
  • RQ4RQ4:测试设计师代理生成的测试的准确性如何?
  • RQ5RQ5:测试在代码覆盖方面的充分性如何?
  • RQ6RQ6:程序员与测试设计师的角色应该在不同代理之间分离吗?

主要发现

  • AgentCoder 在所有数据集和模型上持续超越基础 LLM 与优化基线。
  • 在 GPT-4 下,AgentCoder 在各数据集上的平均 pass@1 为 91.5%(GPT-4 单独为 59.7%)。
  • AgentCoder 显著提升 GPT-3.5-turbo:HumanEval 与 MBPP 的 pass@1 为 79.9%,而 GPT-3.5-turbo 单独为 57.3%。
  • 测试设计师代理产出高度准确的测试用例(HumanEval 87.8%,MBPP 89.9%)与高测试覆盖(前五个测试覆盖 84.7–87.5%)。
  • 单代理设置在 pass@1、测试准确性与测试覆盖方面均不及多代理设计。
  • 消融研究显示分离的代码生成与测试设计角色相较于统一的单代理配置,带来显著的性能提升。
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.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。