arXiv:2509.16198cs.CLcs.AI2025-09被引 17

用图结构统一规划代码库生成,解决大模型造不出完整项目的难题。

RPG: A Repository Planning Graph for Unified and Scalable Codebase Generation

  • 构建仓库规划图(RPG)替代模糊的自然语言描述,实现结构化长期规划。
  • 生成近3.6万行代码,比最强基线大3.9倍,测试通过率提升35.8个百分点。
  • 适合需要自动化构建复杂软件系统的研发团队使用。

大型语言模型擅长生成单个函数或文件,但从零开始生成完整代码库仍是核心挑战。这需要在两个层面进行规划:确定要构建的功能与模块(提案阶段),以及定义其具体实现(实施阶段)。现有方法依赖自然语言规划,常导致规格不清晰、组件错位和设计脆弱。为此,我们提出仓库规划图(RPG),一种统一编码能力、文件结构、数据流与函数的图结构表示。通过用显式蓝图替代自由文本,RPG实现一致的长程规划。基于此,我们开发了零仓库(ZeroRepo)框架,分三阶段运行:提案级规划、实施级构建与图引导代码生成及测试验证。为评估,我们构建了包含六个真实项目、共1052个任务的RepoCraft基准。在该基准上,ZeroRepo平均生成3.6万行代码与44.5万代码标记,是最强基线(Claude Code)的3.9倍,其他基线的68倍;覆盖率达81.5%,测试准确率69.7%,分别优于Claude Code 27.3与35.8个百分点。分析表明,RPG能建模复杂依赖关系,支持近线性扩展的高级规划,并提升代理对代码库的理解与定位速度。数据与代码已开源于https://github.com/microsoft/RPG-ZeroRepo。

原文摘要 · Abstract (English)

Large language models excel at generating individual functions or single files of code, yet generating complete repositories from scratch remains a fundamental challenge. This capability is key to building coherent software systems from high-level specifications and realizing the full potential of automated code generation. The process requires planning at two levels: deciding what features and modules to build (proposal stage) and defining their implementation details (implementation stage). Current approaches rely on natural language planning, which often produces unclear specifications, misaligned components, and brittle designs due to its inherent ambiguity and lack of structure. To address these limitations, we introduce the Repository Planning Graph (RPG), a structured representation that encodes capabilities, file structures, data flows, and functions in a unified graph. By replacing free-form natural language with an explicit blueprint, RPG enables consistent long-horizon planning for repository generation. Building on RPG, we develop ZeroRepo, a graph-driven framework that operates in three stages: proposal-level planning, implementation-level construction, and graph-guided code generation with test validation. To evaluate, we construct RepoCraft, a benchmark of six real-world projects with 1,052 tasks. On RepoCraft, ZeroRepo produces nearly 36K Code Lines and 445K Code Tokens, on average 3.9$\times$ larger than the strongest baseline (Claude Code), and 68$\times$ larger than other baselines. It achieves 81.5% coverage and 69.7% test accuracy, improving over Claude Code by 27.3 and 35.8 points. Further analysis shows that RPG models complex dependencies, enables more sophisticated planning through near-linear scaling, and improves agent understanding of repositories, thus accelerating localization. Our data and code are available at https://github.com/microsoft/RPG-ZeroRepo.

代码生成图结构自动化规划

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。