TL;DR
Finding the exact lines of code causing a software bug—a task called code localization—is a major bottleneck for AI software engineers because source code shows what a system does right now, not why it was built that way. This paper introduces Co-Locator, a framework where an AI agent analyzing static code structure teams up with a "historian" AI agent navigating a knowledge graph of past commits, pull requests, and developer discussions. By combining structural logic with historical intent, Co-Locator outperforms 12 state-of-the-art baselines and significantly boosts downstream automated bug fixing.
What Problem Does This Paper Address?
Imagine being dropped into a massive, unfamiliar codebase at 5 PM on a Friday to fix an obscure bug. Looking only at the current source code tells you how functions call each other, which is helpful, yet incomplete. Often, the real clue lies in the repository's history: a pull request (PR) from six months ago explaining a tricky workaround, or a commit message detailing why a variable was deprecated.
Current AI approaches to code localization generally fall into two camps. Some build code graphs using Abstract Syntax Tree (AST) parsing to map out structural dependencies (which functions call what), completely ignoring the repository's history. Others let LLM agents search raw commit logs or past issues, but treat these records as isolated, unstructured text snippets. Because they miss the web of connections—like how Issue A sparked Discussion B, which was resolved by PR C—agents get lost in fragmented history and miss the overarching design rationale.
Methods
To bridge static code structure with evolutionary history, the authors propose Co-Locator, a framework powered by two distinct graphs and three specialized LLM agents.
First, the system builds its twin maps:
- The Code Graph (CG): Built via standard AST parsing, mapping files, classes, and functions. Unlike prior work that stops at the function level, Co-Locator extends this graph to include variables and external libraries to catch data-level and dependency bugs.
- The Knowledge Graph (KG): This is the core structural novelty. Starting with historical issues/PRs similar to the current bug (strictly before the bug's timestamp to prevent data leakage), Co-Locator links cross-referenced records, PRs, commits, and modified symbols into an "issue-centric backbone." Next, an LLM summarizes these records and extracts semantic triplets—like
(get_type(), RAISES, ValueError)—capturing developer intent and design choices across fragmented logs.
Next, three agents collaborate to find the bug:
- Retriever Agent: Acts as the scout. It uses hybrid search (keywords + embeddings) to give initial starting locations, corrects invalid tool-call arguments, and fetches supplemental locations at the very end.
- Code Graph (CG) Agent: Navigates the static code structure. When it hits a conceptual wall—say, wondering why a certain library or layout property behaves weirdly—it asks the KG agent.
- Knowledge Graph (KG) Agent: Traverses the historical graph to answer the CG agent's questions, synthesizing past fix patterns and developer discussions.
Finally, the top predictions are refined using a bottom-up LLM reranking strategy (denoted as Co-Locator$^+$).
Datasets
The authors evaluate Co-Locator on two existing Python-focused benchmarks (no new datasets are introduced, and no models are fine-tuned):
- LocBench: Contains 560 real-world GitHub issues spanning bug reports, feature requests, performance issues, and security vulnerabilities.
- SWE-Bench-Live (Lite subset): Filtered following LocBench's criteria to 244 instances modifying up to 5 files and 10 functions.
Crucially, both datasets feature issues created after October 2024. By pairing Co-Locator with backbone LLMs whose knowledge cutoffs predate the benchmarks (GPT-4o-2024-08-06 and Qwen2.5-Coder-32B-Instruct), the evaluation avoids data contamination.
Key Insights and Ideas
- History breaks literal-keyword tunnel vision: In a compelling case study on
WeasyPrint(a CSS layout bug involvingoverflow: hiddeninside a flexbox), an agent without the Knowledge Graph fixated on the wordoverflowand guessed the wrong files. With the KG, the agent learned that past flexbox overflow bugs were actually solved by changing child element display properties toblock—leading it straight toblock.pyand the exact ground-truth function. - Role separation beats a generalist agent: Merging the CG and KG agents into a single omni-agent degrades performance across all metrics. Giving one agent the job of structural code detective and another the job of historian keeps their reasoning focused.
- More exploration isn't always better: Increasing the CG agent's budget from 30 to 50 tool calls actually caused slight performance dips. In one instance, an agent found the exact right functions by step 23, kept wandering because it had budget left, and talked itself out of the right answer! Strategic tool use matters more than raw step count.
Key Results
Co-Locator$^+$ consistently outperforms all 12 baselines—including dense code retrievers, procedural workflows (Agentless), and graph-guided agents (LocAgent, CoSIL, OrcaLoca)—across file, module, and function granularities.
- Localization Accuracy: Using Qwen2.5, Co-Locator$^+$ hits 86.5% File Acc@10 and 64.3% Function Acc@15 on SWE-Bench-Live, alongside 88.0% File Acc@10 and 68.9% Function Acc@15 on LocBench (representing 3.0%–4.6% average relative gains over the strongest baselines).
- Resilience to Complexity: While all methods struggle more as bugs span more functions, Co-Locator maintains a clear lead even on complex issues requiring edits to 6+ functions.
- Speed and Cost Efficiency: Even without the LLM reranker, Co-Locator$^-$ beats all other agentic baselines while costing less ($0.17–$0.21 per instance) and running faster (~3.3 seconds average runtime per instance).
- Better Localization = Better Bug Fixes: When feeding localized targets into an automated patch generator (Agentless) on SWE-Bench-Live, Co-Locator$^+$ achieves a 13.1% resolve rate—an 18% relative improvement over the next-best baseline (11.1%) and remarkably close to the 14.8% Oracle upper bound where ground-truth locations are handed over directly.
Limitations and Future Work
Currently, Co-Locator's AST parser is built specifically for Python, limiting its immediate use to Python repositories; the authors plan to expand support to languages like Rust and Java. Additionally, the Knowledge Graph currently only mines development history (issues, PRs, commits). Future work aims to weave documentation and multimodal codebase resources into the graph, as well as pass these historical insights directly to code-generation agents to build an end-to-end automated program repair system.
Summary updated