LocAgent: Graph-Guided LLM Agents for Code Localization

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

arXiv:2503.09089 · 2026-07-27 공개 · arXiv · PDF

llm-agents benchmark-evaluation multi-hop-reasoning graph-guided qwen-coder software-maintenance github-issue-resolution code-localization

Abstract

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.

한국어 요약

한 줄 요약

LocAgent는 그래프 기반 인덱싱을 통해 코드 로컬라이제이션 성능을 향상시키는 LLM 에이전트 프레임워크로, 92.7%의 파일 수준 정확도를 달성한다.

핵심 기여도

핵심 아이디어

LocAgent는 코드 로컬라이제이션 문제를 해결하기 위해 코드베이스를 **지향된 이질그래프**로 표현하는 새로운 접근법을 제시한다. 기존 방법은 코드베이스 전체를 벡터화하거나 단순한 텍스트 매칭에 의존해 복잡한 의존성을 포착하지 못했지만, LocAgent는 **파일, 클래스, 함수**를 노드로, **import, 호출, 상속**을 엣지로 구성한 그래프를 통해 구조적 정보를 유지하면서도 LLM 에이전트가 효과적으로 탐색할 수 있도록 한다.

이 그래프는 **SearchEntity**, **TraverseGraph**, **Hops** 등 다양한 도구와 함께 작동하여, 문제 설명에서 직접적으로 언급되지 않은 코드 영역까지 추적할 수 있는 **다중 홉 추론**을 가능하게 한다. 특히, **SearchEntity 도구 제거 시 정확도가 감소**함으로써 이 도구의 중요성을 입증하며, **Hops=1로 제한하면 함수 수준 정확도가 급격히 하락**함으로써 다중 홉 탐색의 필수성을 강조한다.

기술적 접근법

주요 결과

의의 및 한계

LocAgent는 코드 로컬라이제이션 문제를 해결하기 위한 **구조 인식 그래프 기반 접근법**을 제시하며, 기존 방법 대비 **높은 정확도와 낮은 비용**을 동시에 달성한다. 특히, **Qwen-2.5-Coder-Instruct-32B** 모델을 사용해 **SOTA 모델과 유사한 성능**을 보이며, 오픈소스 모델의 실용성을 입증한다. 또한, **Loc-Bench**를 통해 기존 데이터 오염 문제를 해결한 새로운 평가 기준을 제시한다.

하지만, **Loc-Bench에서 버그 리포트 외의 다른 유지보수 작업**(예: 기능 추가, 성능 최적화)에서 성능이 낮은 것으로 나타나, **더 균형 잡힌 훈련 데이터**가 필요하다는 한계가 드러난다. 또한, **TraverseGraph 도구의 제거 시 성능 저하**는 그래프 구조의 중요성을 강조하며, 그래프 기반 접근법이 필수적임을 보여준다.

실용적 활용

LocAgent는 **소프트웨어 유지보수**, **자동화된 코드 수정**, **AI 기반 개발 도구**에 적용 가능하다. 특히, **비용 효율적인 오픈소스 모델**을 사용하면서도 높은 정확도를 유지하므로, **중소 개발 팀이나 예산 제한이 있는 프로젝트**에 유용하다. 또한, **Loc-Bench**를 통해 지속적으로 평가 데이터를 업데이트할 수 있어, **최신 코드베이스와 모델 변화에 대응하는 연구 및 개발 환경** 구축에 활용할 수 있다.