RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graph

Siru Ouyang, Wenhao Yu, Kaixin Ma, Zilin Xiao, Zhihan Zhang, Mengzhao Jia, Jiawei Han, Hongming Zhang, Dong Yu

RepoGraph is a plug-in module designed to help Large Language Models (LLMs) navigate complex software engineering tasks by building a line-level dependency graph of an entire code repository. By providing fine-grained, repository-wide context through "ego-graphs," RepoGraph significantly boosts the performance of existing AI agents and procedural frameworks, setting a new state-of-the-art for open-source solutions on the SWE-bench.

The Challenge of Repository-Level Coding

While LLMs excel at writing isolated functions, they often struggle with real-world AI Software Engineering (AI SE). In professional settings, code is rarely confined to a single file; it exists within a massive web of interdependent modules, libraries, and files.

Current approaches to AI SE generally fall into two traps:

  1. Coarse Retrieval: Standard Retrieval-Augmented Generation (RAG) often operates at the file level. This introduces excessive "noise" and misses the specific semantic links between a function call in one file and its definition in another.
  2. Local Optimums: AI agents typically browse repositories one file at a time. Without a "global map" of how the codebase fits together, they frequently get lost or fail to anticipate the ripple effects of a bug fix.

Moving from function-level coding to repository-level problem solving requires a deep understanding of intricate dependencies and the ability to navigate complex codebases without introducing new issues.

How RepoGraph Works

RepoGraph acts as a navigational "GPS" for LLMs. It constructs a structured representation of the repository through three main steps:

  1. Line-level Parsing: Using tree-sitter, RepoGraph parses every relevant code file (e.g., .py files) to identify "definitions" (where a class or function is created) and "references" (where it is called).
  2. Project-dependent Filtering: To maintain a clean context window, the system filters out noise like Python built-ins (e.g., len()) and third-party library calls, focusing strictly on the project's internal logic.
  3. Graph Organization: It builds a graph where nodes represent lines of code and edges represent relationships, such as invoke (one line calls a function defined elsewhere) or contain (a class contains a specific method).

When an AI agent or framework needs information about a specific keyword or module, RepoGraph retrieves a $k$-hop ego-graph—a neighborhood of functionally related code lines. This graph is flattened into a text format the LLM can easily process, allowing the model to see exactly how a specific piece of code interacts with the rest of the system.

The RepoGraph construction and integration workflow

Key Insights and Results

RepoGraph is framework-agnostic and designed as a plug-in. It has been successfully integrated into both procedural frameworks (like Agentless) and agentic frameworks (like SWE-agent). The authors evaluated RepoGraph using two primary benchmarks: SWE-bench (Lite), which tests an agent's ability to resolve real-world GitHub issues, and CrossCodeEval, which tests cross-file code completion.

Unlike traditional RAG, which relies on vector similarity, RepoGraph uses hard-coded dependencies to find code that is actually connected. Operating at the line level provides a "Goldilocks" granularity—file-level context is too broad, while function-level is too narrow. This precision allows the LLM to trace execution flow accurately.

Quantitative results showing RepoGraph's impact on various baselines

RepoGraph provided a consistent performance boost across every framework and LLM tested (including GPT-4, GPT-4o, and Claude 3.5 Sonnet):

  • New State-of-the-Art: By plugging RepoGraph into the Agentless framework, the system achieved a 29.67% resolve rate on SWE-bench-Lite, the highest among open-source frameworks at the time of publication.
  • Efficiency Gains: On average, RepoGraph provided a 32.8% relative improvement in success rates across baselines.
  • Localization Accuracy: It significantly improved the model's ability to find the correct file and function to edit. For example, it boosted the file-level localization accuracy of the RAG baseline from 47.3% to 51.7%.
  • Cost-Effective: While adding more context usually increases token costs, the performance gains far outweighed the marginal increase in inference price.

Limitations and Future Work

Currently, RepoGraph is optimized for Python. While the underlying logic is transferable, new parsing schemes are required for languages like C++ or JavaScript. Additionally, RepoGraph currently builds a static graph. Future iterations aim to develop a dynamic version that updates in real-time as the AI agent modifies the codebase. Finally, while experiments heavily utilized proprietary models like GPT-4, further evaluation is needed to assess RepoGraph's compatibility with open-source LLMs like Llama-3.

Summary updated

BibTeX
@inproceedings{ouyang2025repograph,
  author = {Siru Ouyang and Wenhao Yu and Kaixin Ma and Zilin Xiao and Zhihan Zhang and Mengzhao Jia and Jiawei Han and Hongming Zhang and Dong Yu},
  title = {{RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graph}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=dw9VUsSHGB},
}
Figure