arXiv:2603.20299cs.SEcs.AI2026-03被引 2

用分层抽象与多智能体协作,让大模型更懂复杂理论代码的架构逻辑。

HCAG: Hierarchical Abstraction and Retrieval-Augmented Generation on Theoretical Repositories with LLMs

  • 分层构建理论-架构-实现知识库,引导生成从整体到模块的结构化流程。
  • 在博弈论系统生成任务中,代码质量与架构一致性显著优于现有方法。
  • 适合需要高结构化代码生成的科研与工程场景,如算法系统开发。

现有代码检索增强生成(RAG)方法难以捕捉复杂理论驱动代码库(如算法博弈论领域)中的高层架构模式与跨文件依赖,导致抽象概念与可执行实现之间存在持续的语义与结构鸿沟。为此,我们提出分层代码/架构引导智能体生成框架(HCAG),将仓库级代码生成重构为分层知识上的结构化规划过程。HCAG采用两阶段设计:离线分层抽象阶段递归解析代码仓库与对齐的理论文本,构建多粒度语义知识库,显式关联理论、架构与实现;在线分层检索与脚手架生成阶段则采用自顶向下的逐层检索,指导大模型按‘架构-模块’顺序生成。为提升鲁棒性与一致性,引入受合作博弈启发的多智能体讨论机制。理论分析表明,自适应节点压缩的分层抽象相较平面与迭代式RAG基线具有成本最优性。在多样化博弈论系统生成任务上的实验显示,HCAG在代码质量、架构一致性与需求通过率上显著超越代表性仓库级方法。此外,HCAG生成的大规模对齐理论-实现数据集,可通过后训练有效增强领域专用大模型。尽管在算法博弈论中验证,该范式也为其他领域结构化代码库的挖掘、复用与生成提供通用蓝图。

原文摘要 · Abstract (English)

Existing Retrieval-Augmented Generation (RAG) methods for code struggle to capture the high-level architectural patterns and cross-file dependencies inherent in complex, theory-driven codebases, such as those in algorithmic game theory (AGT), leading to a persistent semantic and structural gap between abstract concepts and executable implementations. To address this challenge, we propose Hierarchical Code/Architecture-guided Agent Generation (HCAG), a framework that reformulates repository-level code generation as a structured, planning-oriented process over hierarchical knowledge. HCAG adopts a two-phase design: an offline hierarchical abstraction phase that recursively parses code repositories and aligned theoretical texts to construct a multi-resolution semantic knowledge base explicitly linking theory, architecture, and implementation; and an online hierarchical retrieval and scaffolded generation phase that performs top-down, level-wise retrieval to guide LLMs in an architecture-then-module generation paradigm. To further improve robustness and consistency, HCAG integrates a multi-agent discussion inspired by cooperative game. We provide a theoretical analysis showing that hierarchical abstraction with adaptive node compression achieves cost-optimality compared to flat and iterative RAG baselines. Extensive experiments on diverse game-theoretic system generation tasks demonstrate that HCAG substantially outperforms representative repository-level methods in code quality, architectural coherence, and requirement pass rate. In addition, HCAG produces a large-scale, aligned theory-implementation dataset that effectively enhances domain-specific LLMs through post-training. Although demonstrated in AGT, HCAG paradigm also offers a general blueprint for mining, reusing, and generating complex systems from structured codebases in other domains.

代码生成分层建模多智能体大模型应用

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