Table of Contents
Fetching ...

GraphCodeAgent: Dual Graph-Guided LLM Agent for Retrieval-Augmented Repo-Level Code Generation

Jia Li, Xianjie Shi, Kechi Zhang, Ge Li, Zhi Jin, Lei Li, Huangzhao Zhang, Jia Li, Fang Liu, Yuwei Zhang, Zhengwei Tao, Yihong Dong, Yuqi Zhu, Chongyang Tao

TL;DR

GraphCodeAgent tackles repo-level code generation by bridging natural language requirements with repository-embedded implementations. It introduces two interconnected graphs, the Requirement Graph (RG) and the Structural-Semantic Code Graph (SSCG), to capture requirement relationships and code dependencies, enabling a dual-graph guided LLM agent with a unified toolset to perform multi-hop retrieval. The approach retrieves implicit code elements such as invoked APIs and multi-hop snippets, as well as explicit code like semantically similar code and up-to-date external knowledge via web search, guided by ReAct reasoning. Empirical results on DevEval and CoderEval show substantial improvements over state-of-the-art baselines across multiple LLMs, including reasoning models, with particularly strong gains on tasks requiring cross-file dependencies and complex repository contexts, demonstrating practical impact for real-world software development.

Abstract

Writing code requires significant time and effort in software development. To automate this process, researchers have made substantial progress for code generation. Recently, large language models (LLMs) have demonstrated remarkable proficiency in function-level code generation, yet their performance significantly degrades in the real-world software development process, where coding tasks are deeply embedded within specific repository contexts. Existing studies attempt to use retrieval-augmented code generation (RACG) approaches to mitigate this demand. However, there is a gap between natural language (NL) requirements and programming implementations. This results in the failure to retrieve the relevant code of these fine-grained subtasks. To address this challenge, we propose GraphCodeAgent, a dual graph-guided LLM agent for retrieval-augmented repo-level code generation, bridging the gap between NL requirements and programming implementations. Our approach constructs two interconnected graphs: a Requirement Graph (RG) to model requirement relations of code snippets within the repository, as well as the relations between the target requirement and the requirements of these code snippets, and a Structural-Semantic Code Graph (SSCG) to capture the repository's intricate code dependencies. Guided by this, an LLM-powered agent performs multi-hop reasoning to systematically retrieve all context code snippets, including implicit and explicit code snippets, even if they are not explicitly expressed in requirements. We evaluated GraphCodeAgent on three advanced LLMs with the two widely-used repo-level code generation benchmarks DevEval and CoderEval. Extensive experiment results show that GraphCodeAgent significantly outperforms state-of-the-art baselines.

GraphCodeAgent: Dual Graph-Guided LLM Agent for Retrieval-Augmented Repo-Level Code Generation

TL;DR

GraphCodeAgent tackles repo-level code generation by bridging natural language requirements with repository-embedded implementations. It introduces two interconnected graphs, the Requirement Graph (RG) and the Structural-Semantic Code Graph (SSCG), to capture requirement relationships and code dependencies, enabling a dual-graph guided LLM agent with a unified toolset to perform multi-hop retrieval. The approach retrieves implicit code elements such as invoked APIs and multi-hop snippets, as well as explicit code like semantically similar code and up-to-date external knowledge via web search, guided by ReAct reasoning. Empirical results on DevEval and CoderEval show substantial improvements over state-of-the-art baselines across multiple LLMs, including reasoning models, with particularly strong gains on tasks requiring cross-file dependencies and complex repository contexts, demonstrating practical impact for real-world software development.

Abstract

Writing code requires significant time and effort in software development. To automate this process, researchers have made substantial progress for code generation. Recently, large language models (LLMs) have demonstrated remarkable proficiency in function-level code generation, yet their performance significantly degrades in the real-world software development process, where coding tasks are deeply embedded within specific repository contexts. Existing studies attempt to use retrieval-augmented code generation (RACG) approaches to mitigate this demand. However, there is a gap between natural language (NL) requirements and programming implementations. This results in the failure to retrieve the relevant code of these fine-grained subtasks. To address this challenge, we propose GraphCodeAgent, a dual graph-guided LLM agent for retrieval-augmented repo-level code generation, bridging the gap between NL requirements and programming implementations. Our approach constructs two interconnected graphs: a Requirement Graph (RG) to model requirement relations of code snippets within the repository, as well as the relations between the target requirement and the requirements of these code snippets, and a Structural-Semantic Code Graph (SSCG) to capture the repository's intricate code dependencies. Guided by this, an LLM-powered agent performs multi-hop reasoning to systematically retrieve all context code snippets, including implicit and explicit code snippets, even if they are not explicitly expressed in requirements. We evaluated GraphCodeAgent on three advanced LLMs with the two widely-used repo-level code generation benchmarks DevEval and CoderEval. Extensive experiment results show that GraphCodeAgent significantly outperforms state-of-the-art baselines.

Paper Structure

This paper contains 32 sections, 1 equation, 5 figures, 7 tables.

Figures (5)

  • Figure 1: Comparison between standalone function-level code generation and real-world repo-level code generation. Repo-level code generation invokes the code snippets predefined in the repository.
  • Figure 2: Retrieved knowledge of existing RACG approaches and GraphCodeAgent. Our approach can effectively retrieve implicit and explicit knowledge even if they are not directly mentioned in the target requirement.
  • Figure 3: An illustration of the repo-level code generation task, as well as the relevant implicit knowledge (V) of the target requirement in the current repository.
  • Figure 4: Overview of GraphCodeAgent.
  • Figure 5: An example of the retrieved knowledge and generated code by GraphCodeAgent.