arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2503.09089cs.SEcs.AIcs.CL
收藏

LocAgent:用于代码定位的图引导LLM智能体

LocAgent: Graph-Guided LLM Agents for Code Localization

Yale University(耶鲁大学);University of Southern California(南加州大学);Stanford University(斯坦福大学);All Hands AI

Zhaoling Chen, Xiangru Tang, Gangda Deng, Fang Wu, Jialong Wu, Zhiwei Jiang, Viktor Prasanna, Arman Cohan, Xingyao Wang

AI总结:

提出LocAgent框架,通过将代码库解析为有向异构图以捕获代码结构与依赖关系,引导LLM智能体进行多跳推理实现精准代码定位,在降低86%成本的同时达到SOTA性能并提升下游任务解决率。

摘要:

代码定位——即准确识别代码库中需要进行修改的位置——是软件维护中一项基础且具有挑战性的任务。现有方法在识别相关代码段时,难以高效地导航复杂的代码库。其挑战在于将自然语言问题描述与合适的代码元素相连接,这通常需要跨层级结构和多重依赖进行推理。我们提出了LocAgent,一个通过基于图的表示来解决代码定位的框架。通过将代码库解析为有向异构图,LocAgent创建了一种轻量级的表示,能够捕获代码结构(文件、类、函数)及其依赖关系(导入、调用、继承),使LLM智能体能够通过强大的多跳推理有效地搜索和定位相关实体。在真实世界基准上的实验结果表明,我们的方法显著提升了代码定位的准确率。值得注意的是,我们使用微调后的Qwen-2.5-Coder-Instruct-32B模型的方法,以大幅降低的成本(约减少86%)取得了与SOTA专有模型相当的结果,在文件级定位上达到了92.7%的准确率,同时在多次尝试(Pass@10)中将下游GitHub issue解决成功率提高了12%。我们的代码可在https://github.com/gersteinlab/LocAgent获取。

英文摘要:

Code localization--identifying precisely where in a codebase changes need to be made--is a fundamental yet challenging task in software maintenance. Existing approaches struggle to efficiently navigate complex codebases when identifying relevant code sections. The challenge lies in bridging natural language problem descriptions with the appropriate code elements, often requiring reasoning across hierarchical structures and multiple dependencies. We introduce LocAgent, a framework that addresses code localization through graph-based representation. By parsing codebases into directed heterogeneous graphs, LocAgent creates a lightweight representation that captures code structures (files, classes, functions) and their dependencies (imports, invocations, inheritance), enabling LLM agents to effectively search and locate relevant entities through powerful multi-hop reasoning. Experimental results on real-world benchmarks demonstrate that our approach significantly enhances accuracy in code localization. Notably, our method with the fine-tuned Qwen-2.5-Coder-Instruct-32B model achieves comparable results to SOTA proprietary models at greatly reduced cost (approximately 86% reduction), reaching up to 92.7% accuracy on file-level localization while improving downstream GitHub issue resolution success rates by 12% for multiple attempts (Pass@10). Our code is available at https://github.com/gersteinlab/LocAgent.

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

↑