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.
Figures & tables
Figure 1: Phase I Pipeline: Recursive Abstraction & Hierarchical Summarization. For each target codebase, HCAG recursively extracts logical summaries (green and yellow blocks) from the underlying textual content (orange blocks). At each level, the original content (index) and its summary are aggregated upward until the root node is reached. For nodes exceeding a configurable depth threshold, compression is applied (indicated by ellipsis): a placeholder label is generated, which can be expanded on-demand during later retrieval when the node is first accessed.
Figure 2: Phase II Pipeline: Hierarchical Retrieval and Scaffolded Generation. Given a user task instruction, the LLM evaluates the relevance of each retrieved node with respect to the task. If a node is fully relevant, its content is returned; if it is irrelevant or a leaf node, retrieval along that branch terminates. More commonly, a node is partially relevant, triggering task decomposition over its sub-nodes and recursive retrieval. Encountering a compressed placeholder node initiates on-demand expansion using the Phase I abstraction procedure to generate structured summary for the subtree. This recursive process continues(gray boxes denote parent nodes, green boxes denote child nodes with identical internal structure) until the structured codebase abstraction has been sufficiently traversed to support generation.
Method
CQ
TS
RPR
AT (s)
baseline
0.596
0.010
0.02
148.10
paragraph
0.562
0.015
0.06
164.55
advanced
0.639
0.198
0.24
1609.89
arks
0.619
0.248
0.41
1190.43
coderag
0.671
0.460
0.32
1200.21
pkg
0.728
0.267
0.35
1908.80
Table 1: Results of the main experiment comparing HCAG with baseline methods on framework generation for game-theoretic scenarios.
Methods
CQ
TS
RPR
AT (s)
hierarchical-2
0.650
0.298
0.32
1323.20
hierarchical-3
0.755
0.410
0.47
2208.38
hierarchical-4
0.788
0.525
0.60
3235.11
hierarchical-6
0.795
0.541
0.60
3569.46
hierarchical-4-0(1)
0.769
0.505
0.53
2826.78
hierarchical-4-5(2)
0.788
0.540
0.58
3817.99
Table 2: Consolidated results of ablation studies. The table is divided into four sections, each corresponding to one ablation study: (I) retrieval depth, (II) multi-agent discussion, (III) post-training with hierarchical data, and (IV) different base LLMs. Horizontal lines separate the sections.
Multi-agent LLM systems for code generation face a fundamental routing problem: the optimal orchestration topology depends on the structural complexity of the code under modification, yet existing systems select topologies without consulting the codebase. We present Retrieval-Guided Adaptive Orchestration (RGAO), an architecture that closes this loop by extracting a structural complexity vector from a hierarchical code index before selecting the orchestration topology. RGAO operates within Code-Agent, a multi-agent framework whose sub-agents are governed by formal contracts with six-dimensional budget vectors. Our headline contribution is the composition of two previously separate lines of work -- complexity-conditioned LLM routing and formal resource algebras -- yielding a property neither admits alone: provable budget conservation under retrieval-conditioned dynamic topology selection. Concretely we contribute: (1) a complexity-conditioned topology router that reduces proxy-measured misrouting from 30.1% to 8.2%; (2) a budget algebra with a structural-induction conservation theorem; and (3) a hierarchical code retrieval engine. Empirical evaluation demonstrates sub-millisecond DAG construction and linear tree-index scalability.
Large language model agents have made substantial progress in code generation, yet most existing systems assume a predefined repository architecture. This assumption does not hold in zero-to-all code generation, where an agent must construct an entire software project directly from natural-language requirements while maintaining a modular repository architecture throughout development. We present Repo0, a continuous structural evolution framework for zero-to-all code generation. Repo0 maintains an explicit architectural state instantiated as a Dual-Directed-Acyclic-Graph (Dual-DAG), consisting of a requirement-level DAG, a component-level DAG, and their alignment relation. Starting from natural-language requirements, it iteratively evolves component boundaries through structural actions guided by modularity metrics until structural convergence, after which the converged architecture guides test-driven development code generation. We evaluate Repo0 on six real-world repositories from RepoCraft using GPT-5 mini and DeepSeek V3.2. Repo0 achieves the highest Functionality Coverage and Pass Rate across all settings. Compared with RPG, the strongest repository-planning baseline, Repo0 improves Functionality Coverage by up to 20.08 percentage points and Pass Rate by up to 29.74 percentage points. Ablation and structural-evolution analyses further demonstrate the importance of the Dual-DAG architectural state, modularity-guided structural evolution, and explicit structural convergence.
Silin Chen, Haoyi Teng, Xiaodong Gu +5
Shanghai Jiao Tong University · Chongqing University
Recent advances in large language models have highlighted their potential to automate computational research, particularly reproducing experimental results. However, existing approaches still use fixed sequential agent pipelines with weak global coordination, which limits their robustness and overall performance. In this work, we propose Hierarchical Research Agent System (HiRAS), a hierarchical multi-agent framework for end-to-end experiment reproduction that employs supervisory manager agents to coordinate specialised agents across fine-grained stages. We also identify limitations in the reference-free evaluation of the Paper2Code benchmark and introduce Paper2Code-Extra (P2C-Ex), a refined protocol that incorporates repository-level information and better aligns with the original reference-based metric. We conduct extensive evaluation, validating the effectiveness and robustness of our proposed methods, and observing improvements, including >10% relative performance gain beyond the previous state-of-the-art using open-source backbone models and significantly reduced hallucination in evaluation. Our work is available on GitHub: https://github.com/KOU-199024/HiRAS.
Hanhua Hong, Yizhi LI, Jiaoyan Chen +4
The University of Manchester · Institute for Infocomm Research (I²R), A*STAR · ELLIS Manchester +1