arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2504.10046cs.SE
收藏

GraphCodeAgent:用于检索增强型仓库级代码生成的双图引导LLM智能体

GraphCodeAgent: Dual Graph-Guided LLM Agent for Retrieval-Augmented Repo-Level Code Generation

School of Computer Science, Wuhan University(武汉大学计算机学院);Key Lab of High Confidence Software Technology (PKU), Ministry of Education School of Computer Science, Peking University(北京大学计算机科学与技术系教育部高可信软件技术重点实验室);The University of Hong Kong(香港大学);College of AI, Tsinghua University(清华大学人工智能学院);Beihang University(北京航空航天大学);Institute of Software Chinese Academy of Sciences(中国科学院软件研究所);Peking University(北京大学);Academy of Military Sciences(军事科学院)

Jia Li, Xianjie Shi, Kechi Zhang, Ge Li, Zhi Jin, Lei Li, Huangzhao Zhang, Jia Li, Fang Liu, Yuwei Zhang, Zhengwei Tao, Yihong Dong, Yuqi Zhu, Chongyang Tao

AI总结:

针对LLMs在仓库级代码生成中因上下文依赖导致性能下降的问题,提出GraphCodeAgent双图引导智能体,通过构建需求图和结构语义代码图实现多跳推理检索,在DevEval和CoderEval基准上显著优于基线。

摘要:

在软件开发中编写代码需要大量时间和精力。为了自动化这一过程,研究人员在代码生成领域取得了重大进展。近年来,大型语言模型(LLMs)在函数级代码生成方面展现出卓越能力,但在真实软件开发场景中,由于编码任务深度嵌入特定仓库上下文,其性能显著下降。现有研究尝试使用检索增强型代码生成(RACG)方法缓解这一问题,但自然语言(NL)需求与编程实现之间存在差距,导致无法检索到这些细粒度子任务的相关代码。为应对这一挑战,我们提出GraphCodeAgent,一种用于检索增强型仓库级代码生成的双图引导LLM智能体,以弥合NL需求与编程实现之间的差距。我们的方法构建了两个互联图:需求图(RG)用于建模仓库内代码片段的需求关系,以及目标需求与这些代码片段需求之间的关系;结构语义代码图(SSCG)用于捕捉仓库复杂的代码依赖关系。在此引导下,一个基于LLM的智能体执行多跳推理,系统地检索所有上下文代码片段,包括隐式和显式代码片段,即使它们未在需求中明确表达。我们在三个先进LLM上使用两个广泛使用的仓库级代码生成基准DevEval和CoderEval对GraphCodeAgent进行了评估,大量实验结果表明GraphCodeAgent显著优于现有最先进基线。

英文摘要:

Writing code requires significant time and effort in software development. To automate this process, researchers have made substantial progress for code generation. Recently, large language models (LLMs) have demonstrated remarkable proficiency in function-level code generation, yet their performance significantly degrades in the real-world software development process, where coding tasks are deeply embedded within specific repository contexts. Existing studies attempt to use retrieval-augmented code generation (RACG) approaches to mitigate this demand. However, there is a gap between natural language (NL) requirements and programming implementations. This results in the failure to retrieve the relevant code of these fine-grained subtasks. To address this challenge, we propose GraphCodeAgent, a dual graph-guided LLM agent for retrieval-augmented repo-level code generation, bridging the gap between NL requirements and programming implementations. Our approach constructs two interconnected graphs: a Requirement Graph (RG) to model requirement relations of code snippets within the repository, as well as the relations between the target requirement and the requirements of these code snippets, and a Structural-Semantic Code Graph (SSCG) to capture the repository's intricate code dependencies. Guided by this, an LLM-powered agent performs multi-hop reasoning to systematically retrieve all context code snippets, including implicit and explicit code snippets, even if they are not explicitly expressed in requirements. We evaluated GraphCodeAgent on three advanced LLMs with the two widely-used repo-level code generation benchmarks DevEval and CoderEval. Extensive experiment results show that GraphCodeAgent significantly outperforms state-of-the-art baselines.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑