RPG:統一且可擴展的代碼庫生成之倉庫規劃圖
RPG: A Repository Planning Graph for Unified and Scalable Codebase Generation
September 19, 2025
作者: Jane Luo, Xin Zhang, Steven Liu, Jie Wu, Yiming Huang, Yangyu Huang, Chengyu Yin, Ying Xin, Jianfeng Liu, Yuefeng Zhan, Hao Sun, Qi Chen, Scarlett Li, Mao Yang
cs.AI
摘要
大型语言模型在函数和文件级别的代码生成方面表现出色,然而从零开始生成完整的代码库仍然是一个根本性的挑战。这一过程需要在提案和实现两个层面上进行连贯且可靠的规划,而自然语言由于其模糊性和冗长性,并不适合准确表达复杂的软件结构。为解决这一问题,我们引入了代码库规划图(Repository Planning Graph, RPG),这是一种持久化的表示方法,通过在一个图中编码能力、文件结构、数据流和函数,统一了提案和实现层面的规划。RPG以明确的蓝图取代了模糊的自然语言,实现了长远的规划和可扩展的代码库生成。基于RPG,我们开发了ZeroRepo,一个从零开始生成代码库的图驱动框架。它分为三个阶段运作:提案层面的规划和实现层面的细化以构建图,随后是图引导的代码生成与测试验证。为评估这一设置,我们构建了RepoCraft,一个包含六个真实世界项目、共计1,052个任务的基准测试集。在RepoCraft上,ZeroRepo生成的代码库平均接近36K行代码,约为最强基线(Claude Code)的3.9倍,其他基线的约64倍。它实现了81.5%的功能覆盖率和69.7%的通过率,分别比Claude Code高出27.3和35.8个百分点。进一步分析表明,RPG能够建模复杂的依赖关系,通过近线性扩展实现逐步复杂的规划,并增强大型语言模型对代码库的理解,从而加速代理定位。
English
Large language models excel at function- and file-level code generation, yet
generating complete repositories from scratch remains a fundamental challenge.
This process demands coherent and reliable planning across proposal- and
implementation-level stages, while natural language, due to its ambiguity and
verbosity, is ill-suited for faithfully representing complex software
structures. To address this, we introduce the Repository Planning Graph (RPG),
a persistent representation that unifies proposal- and implementation-level
planning by encoding capabilities, file structures, data flows, and functions
in one graph. RPG replaces ambiguous natural language with an explicit
blueprint, enabling long-horizon planning and scalable repository generation.
Building on RPG, we develop ZeroRepo, a graph-driven framework for repository
generation from scratch. It operates in three stages: proposal-level planning
and implementation-level refinement to construct the graph, followed by
graph-guided code generation with test validation. To evaluate this setting, we
construct RepoCraft, a benchmark of six real-world projects with 1,052 tasks.
On RepoCraft, ZeroRepo produces repositories averaging nearly 36K LOC, roughly
3.9times the strongest baseline (Claude Code) and about 64times other
baselines. It attains 81.5% functional coverage and a 69.7% pass rate,
exceeding Claude Code by 27.3 and 35.8 percentage points, respectively. Further
analysis shows that RPG models complex dependencies, enables progressively more
sophisticated planning through near-linear scaling, and enhances LLM
understanding of repositories, thereby accelerating agent localization.