GraphTool-Instruction: Revolutionizing Graph Reasoning in LLMs through Decomposed Subtask Instruction

Rongzheng Wang, Shuang Liang, Qizhi Chen, Jiasheng Zhang, Ke Qin

Abstract

Large Language Models (LLMs) frequently encounter difficulties with graph reasoning tasks, often resulting in "hallucinations" or failures in algorithmic execution. This paper introduces GraphTool-Instruction, a novel framework that decomposes complex graph reasoning into three manageable subtasks: graph extraction, tool identification, and parameter extraction. By fine-tuning a Llama3-8B model—GraphForge—on the newly curated GTools dataset, we achieve a remarkable 98.4% reasoning accuracy. This performance significantly outperforms GPT-3.5-turbo and rivals state-of-the-art models like GPT-4o.

Introduction

While LLMs excel at natural language processing, their performance on graph-related problems (e.g., shortest path, cycle detection) remains inconsistent. The challenges are twofold: Graph Understanding (GU), the ability to parse topology from text, and Graph Processing (GP), the accurate execution of algorithms. Traditional "Text-Instruction" methods like Chain-of-Thought often fail as graph complexity increases. Meanwhile, standard "Tool-Instruction" methods, where LLMs call external APIs, frequently stumble during the data extraction phase, especially in smaller open-source models.

The GraphTool-Instruction Framework

The core innovation of this work is the "decomposed subtask instruction" approach. Rather than requiring the LLM to solve a problem in a single pass, the framework guides the model through three distinct phases:

  1. Graph-Instruction: This phase focuses on extracting the graph structure. For smaller graphs (Within Limit/WL), it converts natural language descriptions into edge lists. For larger graphs (Exceeds Limit/EL), it identifies the relevant file path, effectively bypassing token limit constraints.
  2. Task-Instruction: The LLM is guided to select the appropriate tool (e.g., shortest_path, max_flow) from a predefined library based on the problem description.
  3. Parameter-Instruction: This specialized prompt ensures the model extracts necessary arguments (e.g., source and target nodes) in the precise format required by the external tool.
The GraphTool-Instruction workflow decomposes the reasoning process into graph extraction, task identification, and parameter extraction.

This modular design is "plug-and-play," allowing it to be used as a prompting strategy for any LLM or as a basis for fine-tuning.

The GTools Dataset

To support this framework, the authors developed GTools, a comprehensive instruction-tuning dataset comprising 40,000 instances across 20 distinct graph reasoning tasks. The dataset includes:

  • Task Diversity: Cycle Detection, Maximum Flow, Topological Sorting, Shortest Path, and more.
  • Graph Complexity: Directed/undirected and weighted/unweighted graphs ranging from 2 to 100 nodes.
  • Instructional Depth: Each instance is formatted to support the three-step decomposition.

Experimental Results

The authors fine-tuned a Llama3-8B model using LoRA to create GraphForge. In comparative evaluations, GraphForge achieved an average accuracy of 98.4%.

Comparison of GraphTool-Instruction against existing graph reasoning methods across different instruction levels.

Key findings include:

  • Superiority over Baselines: GraphForge outperformed traditional Text-Instruction methods by over 40% and GPT-3.5-turbo (with Function Calling) by over 30%.
  • Prompting Robustness: Even without fine-tuning, applying the GraphTool-Instruction prompt to a base Llama3-8B model improved its accuracy to 94%.
  • Generalization: The model demonstrated strong zero-shot performance on "out-of-domain" tasks, such as Bipartite Graph Matching, which were not included in the training set.

Discussion and Future Work

Despite its success, the framework faces limitations with "Graph Mismatch" in extremely large graphs (100+ edges) when described in-context. Additionally, the current iteration is optimized for single-tool calls. Future research will focus on:

  • Sequential Reasoning: Developing frameworks for multi-step graph problems (e.g., finding a path and then calculating flow).
  • Domain Expansion: Applying the methodology to Knowledge Graphs and Recommendation Systems.

In conclusion, GraphTool-Instruction demonstrates that decomposing complex cognitive tasks into structured subtasks allows relatively small LLMs to achieve and even surpass the performance of much larger, proprietary models in specialized domains.

Summary updated

BibTeX
@inproceedings{wang2024graphtool,
  author = {Rongzheng Wang and Shuang Liang and Qizhi Chen and Jiasheng Zhang and Ke Qin},
  title = {{GraphTool-Instruction: Revolutionizing Graph Reasoning in LLMs through Decomposed Subtask Instruction}},
  booktitle = {ACM SIGKDD Conference on Knowledge Discovery and Data Mining},
  year = {2024},
}
Figure