GraphSkill: Documentation-Guided Hierarchical Retrieval-Augmented Coding for Complex Graph Reasoning

Fali Wang, Chenglin Weng, Xianren Zhang, Siyuan Hong, Hui Liu, Suhang WangarXiv 2026

TL;DR

GraphSkill is a novel framework that empowers Large Language Models (LLMs) to solve complex, large-scale graph reasoning tasks by generating and self-debugging executable code. By replacing flat documentation retrieval with a hierarchical tree-traversal agent and introducing logic-aware self-debugging via auto-generated test cases, GraphSkill significantly boosts task accuracy while drastically slashing inference costs.

What Problem Does This Paper Address?

While LLMs excel at many natural language tasks, graph algorithmic reasoning—such as finding shortest paths, detecting cycles, or computing network flows—remains a major hurdle. Purely text-based approaches serialize graphs into text prompts, which quickly fail on large graphs due to context window limits and the degradation of long-horizon reasoning.

To scale up, recent methods decouple the task description from the graph data by having the LLM write code (e.g., using Python's NetworkX library) and offloading the heavy lifting to a program execution environment. However, existing code-based methods suffer from two critical limitations:

  1. Noisy Retrieval: They treat technical documentation as a flat text corpus for Retrieval-Augmented Generation (RAG), which often misses compositional intent or introduces irrelevant noise.
  2. Blind Spots in Debugging: Current code-debugging mechanisms focus almost entirely on fixing runtime or syntax errors, completely ignoring logical errors where the code runs successfully but produces the wrong answer. As the authors' pilot study shows, logical errors actually constitute the vast majority of code failures across prominent models.
Figure 1: (a) Error distribution across various LLMs. (b) Text-based reasoning accuracy (%) across graph scales on ComplexGraph using different LLMs.

Methods

GraphSkill tackles these challenges using a two-agent framework consisting of a Hierarchical Retrieval Agent and a Coding Agent with Self-Debugging.

1. Hierarchical Retrieval Agent

Instead of performing a flat vector search over a disorganized pile of documentation, this agent treats technical documentation as a tree structure (e.g., chapters $\rightarrow$ sub-sections $\rightarrow$ specific API functions). Starting at the root, the agent traverses the tree top-down, using the LLM's semantic understanding to select relevant branches and prune irrelevant ones early. This coarse-to-fine approach isolates the exact required algorithmic functions efficiently.

Figure 3: The hierarchical retrieval agent workflow.

2. Coding Agent with Self-Debugging

Once the correct documentation is retrieved, the coding agent generates the solution. To address logical errors without relying on human-provided test cases, GraphSkill leverages a clever insight: LLMs are nearly 100% accurate at solving graph problems textually if the graph is extremely small (under 5–10 nodes).

The agent autonomously generates a set of miniature graph test cases and solves them via text reasoning to create reliable ground-truth labels. It then generates the candidate code, runs it against these mini test cases in an isolated environment, and iteratively refines the code based on the feedback until all tests pass.

Figure 2: Overview of the Agentic Hierarchical Retrieval- Augmented Self-debugging Coding Framework.

Datasets

The framework was evaluated on two primary benchmarks:

  • GTools (WL and EL): A standard synthetic benchmark used to test an LLM's ability to invoke graph tools across small and large scales.
  • ComplexGraph (Newly Introduced): A challenging new synthetic dataset designed by the authors to test both structural and semantic complexity. It features three subsets:
  • ComplexGraph-S: Small-scale graphs (3 to 200 nodes).
  • ComplexGraph-L: Large-scale graphs (5,000 to 10,000 nodes) to push context limits.
  • ComplexGraph-C: Composite tasks that require chaining multiple primitive graph algorithms together (e.g., finding strongly connected components and then calculating network diameter).

Key Insights and Ideas

  • Logic Errors are the Real Enemy: In advanced models like DeepSeek-V3, 100% of code generation failures on graph tasks are due to logical flaws, not syntax or runtime crashes. Debugging frameworks must evolve to check semantic correctness.
  • Small-Scale Competence as a Label Generator: The realization that LLMs maintain perfect accuracy on tiny graphs allows the system to bootstrap its own unit tests, turning a zero-shot problem into a reliably supervised self-debugging loop.
  • Structure Saves Tokens: Navigating documentation hierarchically acts as an effective noise filter. By filtering out irrelevant API docs early, the framework avoids prompt bloat, which surprisingly makes it cheaper to run than standard flat retrieval methods.

Key Results

  • Superior Accuracy: GraphSkill consistently outperformed competitive baselines. On the highly complex composite dataset (ComplexGraph-C) using the Qwen-2.5-7B model, GraphSkill achieved 73.3% accuracy, significantly outperforming the multi-agent baseline GraphTeam (56.7%).
  • Drastic Cost Reduction: By precisely narrowing down the retrieved documentation, GraphSkill reduced the input token overhead during the coding phase. It achieved the lowest total inference cost among RAG baselines—around $2 \times 10^{-4}$ USD per task—making it both highly accurate and highly economical.
  • Robust Scalability: On truly large-scale graphs (ComplexGraph-L), text-based reasoning accuracy plummeted to near 0%, whereas GraphSkill maintained near-perfect execution accuracy ($\sim$99.1% using DeepSeek-V3.2) by successfully offloading the computation to the generated code.

Limitations and Future Work

Despite its success, the authors note that smaller language models (like 7B variants) still experience a performance gap on composite tasks because they struggle with complex problem-level semantic understanding. Additionally, the framework inherently relies on the availability of well-structured, hierarchical technical documentation; adapting it to poorly documented or un-indexed libraries remains an open challenge for future research.

Summary updated

BibTeX
@misc{wang2026graphskill,
  author = {Fali Wang and Chenglin Weng and Xianren Zhang and Siyuan Hong and Hui Liu and Suhang Wang},
  title = {{GraphSkill: Documentation-Guided Hierarchical Retrieval-Augmented Coding for Complex Graph Reasoning}},
  year = {2026},
  eprint = {2603.06620},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2603.06620},
}
Figure