GraphSkill: Documentation-Guided Hierarchical Retrieval-Augmented Coding for Complex Graph Reasoning
Organizations: The Pennsylvania State University, University Park, Pennsylvania, USA · Michigan State University, East Lansing, Michigan, USA
Abstract
The growing demand for automated graph algorithm reasoning has attracted increasing attention in the large language model (LLM) community. Recent LLM-based graph reasoning methods typically decouple task descriptions from graph data, generate executable code augmented by retrieval from technical documentation, and refine the code through debugging. However, we identify two key limitations in existing approaches: (i) they treat technical documentation as flat text collections and ignore its hierarchical structure, leading to noisy retrieval that degrades code generation quality; and (ii) their debugging mechanisms focus primarily on runtime errors, yet ignore more critical logical errors. To address them, we propose {\method}, an agentic hierarchical retrieval-augmented coding framework that exploits the document hierarchy through top-down traversal and early pruning, together with a self-debugging coding agent that iteratively refines code using automatically generated small-scale test cases. To enable comprehensive evaluation of complex graph reasoning, we introduce a new dataset, {\dataset}, covering small-scale, large-scale, and composite graph reasoning tasks. Extensive experiments demonstrate that our method achieves higher task accuracy and lower inference cost compared to baselines\footnote{The code is available at blue{https://github.com/FairyFali/GraphSkill}.}.
Figures & tables
| Method | Coding | Runtime Debug | Logic Debug | Ret. | Hi. | Non- Human |
| GCoder ( 2025 ) | ✓ | ✓ | ✓ | |||
| GraphTool-Inst. ( 2025b ) | ✓ | ✓ | ||||
| GraphTeam ( 2025 ) | ✓ | ✓ | ✓ | ✓ | ||
| CodeGraph ( 2024 ) | ✓ | |||||
| PIE ( 2025 ) | ✓ | ✓ | ✓ | |||
| Ours | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| ComplexGraph -S | GTools-WL | Avg. | ||||||
| Method | DeepSeek | LLaMA-70B | Qwen-7B | DeepSeek | LLaMA-70B | Qwen-7B | ||
| (i) | Zero-shot | 67.3 | 32.3 | 20.9 | 68.0 | 43.5 | 40.5 | 45.4 |
| Few-shot | 64.6 | 35.0 | 16.4 | 78.5 | 52.0 | 45.5 | 48.7 | |
| CoT | 62.3 | 32.7 | 20.9 | 79.0 | 45.5 | 29.5 | 45.0 | |
| Bag-CoT | 66.4 | 24.6 | 15.5 | 69.5 | 36.0 | 26.5 | 39.8 | |
| (ii) | Zero-shot Coding | 81.8 | 73.2 | 45.4 | 88.0 | 82.5 | 50.0 | 70.1 |
| ComplexGraph -L | GTools-EL | Avg. | ||||||
| Method | DeepSeek | LLaMA-70B | Qwen-7B | DeepSeek | LLaMA-70B | Qwen-7B | ||
| (i) | Zero-shot | 12.4 | 3.8 | 0.0 | 78.9 | 42.2 | 41.1 | 29.7 |
| Few-shot | 13.3 | 2.4 | 0.0 | 83.3 | 62.8 | 48.3 | 35.0 | |
| CoT | 11.9 | 5.7 | 0.0 | 84.4 | 53.9 | 46.1 | 33.7 | |
| Bag-CoT | 8.6 | 3.3 | 0.0 | 71.7 | 33.3 | 24.4 | 23.6 | |
| (ii) | Zero-shot Coding | 85.2 | 66.2 | 39.1 | 93.3 | 94.4 | 48.3 | 71.1 |
| Method | DeepSeek | LLaMA-70B | Qwen-7B | |
| (i) | Zero-shot | 43.3 | 5.6 | 4.4 |
| Few-shot | 43.3 | 4.4 | 2.2 | |
| CoT | 42.2 | 2.2 | 3.3 | |
| Bag-CoT | 55.6 | 0.0 | 11.1 | |
| (ii) | Zero-shot Coding | 64.4 | 56.7 | 6.7 |
| Few-shot Coding | 78.9 | 51.1 | 10.0 |
| Setting | DeepSeek | LLaMA | Qwen | Avg. |
| Full | 96.0 | 96.6 | 82.6 | 91.7 |
| w/o Retrieval | 91.9 | 81.8 | 61.2 | 78.3 |
| w/o Hierarchy | 92.5 | 87.9 | 68.5 | 83.0 |
| w/o Debugging | 94.2 | 96.0 | 69.9 | 86.7 |
| w/o Test cases | 94.2 | 96.0 | 73.0 | 87.7 |
| w/o Ret + Deb | 86.0 | 80.8 | 51.3 | 72.7 |
| Method | Retrieval | Coding | Total |
| TFIDF+Coding | 0 | 9 | 9 |
| SentBERT+Coding | 0 | 9 | 9 |
| GraphTeam | 800 † / 0.1 | 5 | 5 |
| Ours | 2 | 2 | 4 |
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
| Task Name | Instances | Nodes | Edges |
| GTools-WL (Small-scale) | |||
| Maximum Flow | 20 | 12–39 | 34–150 |
| Shortest Path Length | 20 | 10–38 | 37–148 |
| Topological Sort | 10 | 5–37 | 7–265 |
| Node Existence Check | 20 | 12–40 | 38–300 |
| Edge Existence Check | 20 | 6–38 | 19–280 |
| Task | Task Type | #Examples | #Nodes | #Edges |
| Graph Connectivity Check (GCC) | Traversal-Based Reasoning | 674 | 2–200 | 1–19,701 |
| Connected Components Counting (CCC) | Traversal-Based Reasoning | 674 | 2–200 | 1–19,701 |
| Strongly Connected Components Counting (SCCC) | Traversal-Based Reasoning | 550 | 4–200 | 2–18,336 |
| Shortest Path (SP) | Traversal-Based Reasoning | 1,472 | 2–200 | 1–19,503 |
| Eulerian Path Check (EPC) | Graph Property Detection | 1,224 | 2–200 | 1–18,336 |
| Graph Bipartiteness (GB) | Graph Property Detection | 1,224 | 2–200 | 1–18,336 |
| Task | Task Type | #Examples | #Nodes | #Edges |
| Graph Connectivity Check (GCC) | Traversal-Based Reasoning | 45 | 200–8,000 | 5,400–301,158 |
| Connected Components Counting (CCC) | Traversal-Based Reasoning | 45 | 200–8,000 | 5,400–301,158 |
| Strongly Connected Components Counting (SCCC) | Traversal-Based Reasoning | 45 | 200–8,000 | 5,400–315,966 |
| Shortest Path (SP) | Traversal-Based Reasoning | 54 | 200–8,000 | 5,400–284,468 |
| Eulerian Path Check (EPC) | Graph Property Detection | 90 | 200–8,000 | 5,400–315,966 |
| Graph Bipartiteness (GB) | Graph Property Detection | 90 | 200–8,000 | 5,400–315,966 |
| Task Name | Type | #Examples | #Nodes | #Edges | Primitive Tasks |
| Clustering–Shortest Path | Sequential | 572 | 2–200 | 1–19,701 | Shortest Path; Clustering Coefficient |
| SCC–Diameter | Sequential | 550 | 4–200 | 2–18,336 | Strongly Connected Components; Graph Diameter |
| CC-Flow-Clustering | Sequential | 94 | 2–200 | 1–19,701 | Connected Components; Maximum Flow; Clustering Coefficient |
| Pair Tightness Score | Parallel | 339 | 3–200 | 1–18,915 | Shortest Path; Common Neighbors; Clustering Coefficient |
| Bridge Hub Identification | Parallel | 674 | 2–200 | 1–19,701 | Clustering Coefficient; Shortest Path |
| Endpoint-Aware Flow | Parallel | 131 | 8–198 | 5–19,503 | Maximum Flow; Clustering Coefficient |
LLM Reasoning with Graphs
Large language model reasoning with graphs uses structured relationships to support multi-step inference, evidence retrieval, and planning.
See all 200 papers