arXiv:2503.09089cs.SEcs.AI2025-03ACL被引 106

用图结构引导大模型精准定位代码修改位置,效率远超现有方法。

LocAgent: Graph-Guided LLM Agents for Code Localization

  • 将代码库转为有向异构图,支持多跳推理定位代码
  • 在文件级定位上达92.7%准确率,成本降低86%
  • 适合需要高效修复代码的开发者和自动化维护工具

代码定位——精确定位代码库中需修改的位置——是软件维护中的基础但极具挑战的任务。现有方法在复杂代码库中导航时效率低下,主要难点在于将自然语言问题描述与合适的代码元素对齐,常需跨层次结构和多重依赖进行推理。我们提出LocAgent框架,通过图结构表示解决该问题。该框架将代码库解析为有向异构图,构建轻量级表示,捕捉代码结构(文件、类、函数)及其依赖关系(导入、调用、继承),使大语言模型代理能够通过强大的多跳推理有效搜索并定位相关实体。在真实世界基准上的实验表明,该方法显著提升代码定位精度。特别地,使用微调后的Qwen-2.5-Coder-Instruct-32B模型,本方法以约86%的成本降幅达到与顶级专有模型相当的效果,在文件级定位上最高实现92.7%准确率,并使多次尝试下的GitHub问题修复成功率提升12%(Pass@10)。代码已开源:https://github.com/gersteinlab/LocAgent。

原文摘要 · Abstract (English)

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.

代码定位图神经网络大模型应用自动化修复

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。