Skip to main content
QUICK REVIEW

[论文解读] CodeAgent: Autonomous Communicative Agents for Code Review

Daniel Tang, Kisub Kim|arXiv (Cornell University)|Feb 3, 2024
Multi-Agent Systems and NegotiationComputer Science被引用 3
一句话总结

CodeAgent 引入了一种基于大语言模型(LLM)的多智能体框架,用于自动化代码审查,通过使用 QA-Checker 监督智能体模拟协作团队的动态,以保持话题连贯性。该框架在九种编程语言中对漏洞检测的命中率相比最先进模型提升了 41.54 个百分点,尤其在一致性、漏洞和格式分析任务中表现优异。

ABSTRACT

Code review, which aims at ensuring the overall quality and reliability of software, is a cornerstone of software development. Unfortunately, while crucial, Code review is a labor-intensive process that the research community is looking to automate. Existing automated methods rely on single input-output generative models and thus generally struggle to emulate the collaborative nature of code review. This work introduces ool{}, a novel multi-agent Large Language Model (LLM) system for code review automation. CodeAgent incorporates a supervisory agent, QA-Checker, to ensure that all the agents' contributions address the initial review question. We evaluated CodeAgent on critical code review tasks: (1) detect inconsistencies between code changes and commit messages, (2) identify vulnerability introductions, (3) validate code style adherence, and (4) suggest code revision. The results demonstrate CodeAgent's effectiveness, contributing to a new state-of-the-art in code review automation. Our data and code are publicly available (\url{https://github.com/Code4Agent/codeagent}).

研究动机与目标

  • 为解决单模型、非协作式自动化代码审查工具无法模拟真实团队协作动态的局限性。
  • 提升关键代码审查子任务(如一致性检测、漏洞识别和风格验证)的性能。
  • 通过一种基于数学优化的新型 QA-Checker 监督机制,缓解多智能体 LLM 对话中的话题漂移问题。
  • 利用真实世界 GitHub 拉取请求数据和基准数据集,在多种编程语言中评估 CodeAgent 的有效性。

提出的方法

  • CodeAgent 采用多智能体架构,不同智能体模拟代码作者、审查者和决策者等角色,以实现协作式代码审查流程。
  • QA-Checker 智能体通过使用质量评估函数 $\mathcal{Q}$ 和牛顿-拉夫森优化方法,强制所有交互内容与原始审查问题保持相关性,从而防止话题漂移。
  • 系统结合链式思维(CoT)推理与 QA-Checker,生成详细、连贯且上下文准确的审查报告。
  • 系统基于大语言模型(如 GPT-3.5 和 GPT-4)构建,其中 CodeAgent-4.0 在推理能力和长上下文处理方面优于 CodeAgent-3.5。
  • 该框架在合成数据集(Trans-Review、AutoTransform、T5-Review)和 2023 年 4 月之后的九种编程语言的真实 GitHub 数据集上进行了评估。
  • 消融研究通过对比缺少该监督机制的变体(CodeAgent w/o)来隔离 QA-Checker 的影响。

实验结果

研究问题

  • RQ1多智能体 LLM 系统是否能在多种子任务中超越单模型方法,在自动化代码审查中表现更优?
  • RQ2QA-Checker 智能体在协作式代码审查模拟过程中,防止话题漂移并保持连贯性的有效性如何?
  • RQ3引入 QA-Checker 对一致性检测、漏洞分析和格式验证任务的性能提升程度如何?
  • RQ4CodeAgent 在真实世界 GitHub 拉取请求数据中,对多种编程语言的表现如何?
  • RQ5与基线模型和消融变体相比,QA-Checker 对漏洞检测准确率的定量影响是什么?

主要发现

  • 在九种编程语言中,CodeAgent 相比最先进模型,对已合并提交中漏洞问题的命中率提升了 41.54 个百分点。
  • CodeAgent 在整体代码审查指标上优于 CodeBERT 和 ChatGPT,尤其在一致性检测和漏洞识别方面表现更优。
  • 消融研究显示,移除 QA-Checker(即 CodeAgent w/o)后确认率下降——例如,Python 中已合并漏洞的确认率从 14.00% 降至 13.25%,表明 QA-Checker 在提升准确性方面具有关键作用。
  • CodeAgent-4.0 生成的报告显著更详细,以一个 Java 项目为例,其报告行数达 17.7k 行,高于 CodeAgent-3.5 的 15k 行,体现出更强的推理能力和输出质量。
  • 在格式分析方面,CodeAgent 在全部九种语言中均表现出色,证实其在风格和格式验证任务中的稳健性。
  • QA-Checker 采用基于 $\mathcal{Q}$ 和牛顿-拉夫森优化的数学框架,有效减少了无关或偏离主题的回应,保持了多智能体对话的高连贯性。

阅读本论文

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

在 Nubint 中阅读本论文

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