CodeCoR:一种基于大语言模型的代码生成自反思多智能体框架
CodeCoR: An LLM-Based Self-Reflective Multi-Agent Framework for Code Generation
AI总结:
研究针对代码生成中语言模型无法确保代码正确性及多智能体框架工作流性能不稳健的问题,提出CodeCoR框架,通过在不同阶段修剪中间输出减少错误传播,实验证明其优于现有基线。
摘要:
代码生成旨在自动生成满足自然语言需求的代码。像ChatGPT这样的大语言模型在该领域已展现出有效成果,但常无法确保生成代码的句法和语义正确性。近期研究者提出多智能体框架,但其工作流性能不稳健。为此,我们提出CodeCoR,该多智能体框架在不同阶段修剪中间输出以减少顺序代码生成工作流中的错误传播。具体而言,CodeCoR中的四个智能体分别生成提示、代码、测试用例和修复建议,每个智能体生成多个输出并去除低质量的。生成的代码在本地环境中测试,未通过测试用例的代码被发送到修复智能体,编码智能体根据修复建议重新生成代码。最后,返回通过最多生成测试用例的代码给用户。我们在四个广泛使用的数据集上的实验表明,CodeCoR优于现有基线,平均Pass@1分数达到77.13%。
英文摘要:
Code generation aims to produce code that fulfills requirements written in natural language automatically. Large Language Models (LLMs) like ChatGPT have demonstrated promising effectiveness in this area. Nonetheless, the LLMs often fail to ensure the syntactic and semantic correctness of the generated code. Recently, researchers proposed multi-agent frameworks that guide LLMs with different prompts to analyze programming tasks, generate code, and perform testing in a sequential workflow. However, the performance of the workflow is not robust as code generation depends on the performance of each agent. To address this challenge, we propose CodeCoR, a multi-agent framework that prunes intermediate outputs at different stages to reduce error propagation in sequential code generation workflows. Specifically, for a given task description, four agents in CodeCoR generate prompts, code, test cases, and repair advice, respectively. Each agent generates more than one output and prunes away the low-quality ones. The generated code is tested in the local environment: the code that fails to pass the generated test cases is sent to the repair agent, and the coding agent re-generates the code based on repair advice. Finally, the code that passes the highest number of generated test cases is returned to the users. Our experiments on four widely used datasets, HumanEval, HumanEval-ET, MBPP, and MBPP-ET, demonstrate that CodeCoR outperforms existing baselines (e.g., CodeCoT and MapCoder), achieving an average Pass@1 score of 77.13%.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。