arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2603.20299cs.SEcs.AI
收藏

HCAG:基于LLM的理论仓库中层次抽象与检索增强生成

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

Yusen Wu, Xiaotie Deng

AI总结:

HCAG通过层次化抽象与检索增强生成方法,解决复杂理论代码库中高层架构模式和跨文件依赖的捕捉问题,提升代码质量和架构一致性。

摘要:

现有基于检索增强生成(RAG)的代码方法难以捕捉复杂理论驱动代码库中的高层架构模式和跨文件依赖,导致抽象概念与可执行实现之间存在语义和结构差距。为此,我们提出Hierarchical Code/Architecture-guided Agent Generation(HCAG)框架,将仓库级代码生成改造成基于层次化知识的结构化规划过程。HCAG采用两阶段设计:离线层次化抽象阶段递归解析代码仓库和对齐的理论文本,构建多分辨率语义知识库,明确连接理论、架构和实现;在线层次化检索和支撑生成阶段通过自顶向下的逐层检索引导LLM以架构-模块生成范式生成代码。为进一步提高鲁棒性和一致性,HCAG整合了受合作博弈启发的多代理讨论。我们提供理论分析表明,层次化抽象与自适应节点压缩在成本优化方面优于扁平和迭代RAG基线。在多样化的博弈论系统生成任务中,HCAG在代码质量、架构一致性及需求通过率方面显著优于代表性的仓库级方法。此外,HCAG生成了一个大规模、对齐的理论-实现数据集,通过后续训练有效增强领域特定LLM。尽管在博弈论中得到验证,HCAG范式也提供了一个通用蓝图,用于从结构化代码库中挖掘、重用和生成其他领域的复杂系统。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑