用智能代理增强检索,精准定位代码缺陷文件
BLAgent: Agentic RAG for File-Level Bug Localization

- 构建代码结构感知的检索框架,结合路径增强的抽象语法树分块
- 双视角查询转换捕捉错误报告中的结构与行为特征,定位准确率超78%
- 采用受限推理策略,在保证精度前提下降低计算成本18倍以上
Bug定位是基于大语言模型的软件维护中的关键瓶颈,准确识别故障代码对调试、根因分析、任务分配和自动化程序修复(APR)至关重要。文件级定位在分层定位与修复流程中尤为关键,错误的文件选择会传递至后续函数级定位和补丁生成阶段。尽管检索增强生成(RAG)为大模型提供了代码库上下文支持,但现有RAG流程多依赖静态检索,缺乏精准识别故障代码所需的推理能力。本文提出BLAgent,一种新型面向文件级漏洞定位的智能体式RAG框架,融合三项核心设计:(i) 基于路径增强的抽象语法树分块实现代码结构感知的仓库编码;(ii) 双视角查询转换,从错误报告中同时提取结构与行为信号;(iii) 两阶段智能体重排序机制,结合符号检查与证据驱动推理。不同于以往图结构或多跳式智能体方法,BLAgent采用有限推理策略,将大模型的检查与重排序限制在经检索过滤的候选文件集合内,避免开放式仓库遍历,兼顾定位精度与计算开销。在SWE-bench-Lite上,使用开源模型时,其Top-1准确率超过78%,使用闭源模型时超过86%,且成本低于最强基线18倍以上。集成至APR框架后,可使端到端修复成功率提升最高达25%。
原文摘要 · Abstract (English)
Bug localization remains a key bottleneck for large language model (LLM)-based software maintenance, where accurately identifying faulty code is essential for debugging, root cause analysis, triage, and automated program repair (APR). File-level bug localization is especially critical in hierarchical localization and repair pipelines, where incorrect file selection can propagate to downstream stages such as function-level localization and patch generation. While Retrieval-Augmented Generation (RAG) offers a promising way to ground LLMs in repository context, existing RAG pipelines often rely on static retrieval and lack the reasoning needed to accurately identify faulty code. In this work, we present BLAgent, a novel agentic RAG framework for file-level bug localization that integrates three key ideas: (i) code structure-aware repository encoding with path-augmented AST-based chunking, (ii) dual-perspective query transformation that captures both structural and behavioral signals from bug reports, and (iii) two-phase agentic reranking that combines symbolic inspection with evidence-grounded reasoning. Unlike prior graph-based or multi-hop agentic approaches, BLAgent adopts a bounded reasoning strategy that limits LLM-based inspection and reranking to a compact, retrieval-filtered set of candidate files, avoiding open-ended repository traversal. This design balances localization accuracy with computational cost. On SWE-bench-Lite, BLAgent attains over 78% Top-1 accuracy with open-source models and over 86% with a closed-source model, while being over 18x cheaper than the strongest baseline using the same model. When integrated into an APR framework, BLAgent improves end-to-end repair success by up to 25%.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。