BLAgent: Agentic RAG for File-Level Bug Localization
BLAgent is a novel agentic Retrieval-Augmented Generation framework that enhances file-level bug localization through code structure-aware encoding, dual-perspective query transformation, and two-phase agentic reranking, achieving state-of-the-art accuracy on SWE-bench Lite while significantly reducing costs and improving downstream automated program repair success.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
The Big Problem: Finding a Needle in a Haystack
Imagine you are a mechanic (a software developer) trying to fix a broken car. A customer hands you a complaint: "The car makes a weird noise when I turn left."
In the world of software, this complaint is a bug report. The car is a massive code repository containing millions of lines of code (the hay). The specific line of code causing the noise is the needle.
For a long time, AI tools trying to fix these bugs have struggled because they can't find the needle first. If the AI guesses the wrong part of the engine (the wrong file), it will try to fix the wrong thing, and the car will still be broken. This is called Bug Localization.
The Solution: BLAgent (The Super-Detective)
The authors created a new system called BLAgent. Think of it as a super-detective that doesn't just guess; it uses a smart, step-by-step investigation process to find the exact file that needs fixing before trying to repair it.
BLAgent uses a technique called Agentic RAG (Retrieval-Augmented Generation). In plain English, this means the AI doesn't just "hallucinate" an answer; it goes to a library (the code repository), finds the right books (code files), reads them, and then thinks about the answer.
Here is how BLAgent works, broken down into three simple steps:
1. Organizing the Library (Smart Chunking)
Imagine your library is a mess. Books are ripped in half, and pages are glued together randomly. If you ask the librarian for a book about "engines," they might hand you a page that says "engine" but is actually from a cookbook.
- Old Way: Traditional AI splits code into random chunks of text, like tearing a book page by page.
- BLAgent Way: BLAgent uses a structural map (called an AST). It knows that a "function" or a "class" is like a complete chapter. It cuts the code only at the end of these chapters.
- The Secret Sauce: It also stamps the file path (the address of the book) on every page. If the bug report mentions a specific folder name, BLAgent can instantly match that address to the right book.
2. Asking Better Questions (Dual-Perspective Queries)
Imagine you are asking a librarian for help.
- Bad Question: "My car is broken." (Too vague).
- BLAgent's Strategy: It asks two different questions to get the best results:
- The Structural Question: "Which file contains the
turn_signalfunction?" (Looking for specific names and code structures). - The Behavioral Question: "Which file handles the situation where the car makes a noise when turning?" (Looking for the symptoms and behavior).
- The Structural Question: "Which file contains the
By asking both, BLAgent casts a wider net, ensuring it doesn't miss the right file just because the bug report used different words than the code.
3. The Detective's Investigation (Agentic Reranking)
This is the most important part. The library gives BLAgent a list of the top 15 most likely books (files). But which one is actually the culprit?
- Old AI: Picks the first book on the list and tries to fix it.
- BLAgent (The Agent): It acts like a detective. It doesn't just read the cover; it opens the books and looks at the skeleton (the table of contents and chapter titles) of the top candidates.
- It asks itself: "Does this file's structure match the crime?"
- It assigns a score (0 to 10) to each file.
- Then, for the top few suspects, it reads the actual text of the relevant sections to make a final, evidence-based decision.
This "bounded reasoning" means the detective only investigates the most likely suspects, saving time and money, rather than searching the whole library.
Why This Matters: The Repair Shop
The paper tested BLAgent on a famous benchmark called SWE-bench (a collection of real-world software bugs).
- The Result: BLAgent found the correct file to fix 78% to 86% of the time (depending on the AI model used).
- The Comparison: Previous methods found the right file less often.
- The Cost: BLAgent is 18 times cheaper than the previous best method. The old methods were like hiring a team of 100 people to search the library; BLAgent is like hiring one very smart detective with a map.
The Impact on Fixing Bugs:
When BLAgent was plugged into an automated repair system, the system successfully fixed 20% more bugs than before.
- Analogy: If you give a mechanic the wrong engine part, they can't fix the car. If you give them the right part (accurate localization), they can fix it. BLAgent ensures the mechanic gets the right part.
What the Paper Doesn't Say
- It does not claim to fix every bug. About 14% of the time, the correct file was so hidden or the bug report so vague that even BLAgent couldn't find it in the top list.
- It does not claim to be a magic wand for all software. It works best on Python projects (like the ones in the test) and relies on the quality of the bug report.
- It does not say that finding the file is the only step. Once the file is found, the AI still has to write the actual code fix, which can still fail. But finding the file is the biggest hurdle.
Summary
BLAgent is a smarter way for AI to find broken code. Instead of guessing randomly, it organizes the code library better, asks smarter questions, and uses a "detective" step to verify the evidence before making a move. This makes it much faster, cheaper, and more accurate at finding the root cause of software bugs.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.