GraphRouter: A Graph-based Router for LLM Selections

Tao Feng, Yanzhen Shen, Jiaxuan You

Introduction

The "LLM Zoo" is expanding at a breakneck pace. Today, developers have access to hundreds of Large Language Models (LLMs), ranging from nimble 7-billion parameter versions to massive, resource-heavy giants. While larger models generally yield better performance, they are significantly more expensive and slower to run. Conversely, a smaller model might be perfectly adequate for a simple query but fail miserably at complex reasoning tasks.

To navigate this trade-off, "routers" are used to intelligently direct user queries to the most suitable model. However, current routing systems suffer from two main flaws:

  1. Context Blindness: They often treat models as simple IDs or indices, failing to capture the nuanced relationship between a specific task's requirements and a model's unique strengths.
  2. Transductive Limitations: Most existing routers are hard-coded to a fixed set of models. If a new, superior LLM is released, these systems typically require complete, expensive retraining to incorporate it.
Illustration of the LLM routing problem, where the system must predict the performance and cost of assigning a specific query to a given model.

To address these shortcomings, researchers have introduced GraphRouter, a novel inductive graph framework that reframes LLM selection as an edge prediction problem. By modeling the complex relationships between tasks, queries, and models, GraphRouter achieves a substantial performance boost and can adapt to brand-new LLMs without the need for retraining.

The GraphRouter Framework

GraphRouter tackles the routing challenge by constructing a heterogeneous graph that captures the multi-way context between different elements of a query.

The Graph Structure

The framework builds a graph utilizing three distinct types of nodes:

  • Task Nodes: Represent the broader category of the problem (e.g., "Reasoning" or "Summarization").
  • Query Nodes: Represent the specific user input or prompt.
  • LLM Nodes: Represent the available language models (e.g., LLaMA-3, Mixtral).

Edges between these nodes represent interactions. For instance, an edge connecting a Query node to an LLM node contains features that represent the observed performance and computational cost of that model's response to that specific query.

The GraphRouter architecture, detailing the heterogeneous graph of Task, Query, and LLM nodes during training, and its inductive capability to handle new LLM nodes during testing.

Inductive Learning via Descriptions

To make the system inductive—meaning it can seamlessly handle newly released models—the authors abandoned simple one-hot encodings for model IDs. Instead, they leverage natural language descriptions:

  1. A high-end model (GPT-4o) generates a textual description of each task and LLM, detailing its strengths, pricing, and context limits.
  2. These descriptions are embedded using a pre-trained language model (BERT) to initialize the nodes.
  3. When a new LLM is introduced, GraphRouter simply generates a new text embedding for it. The Heterogeneous Graph Neural Network (GNN) then aggregates information from neighboring nodes to predict how this new model will perform, even with zero or "few-shot" prior interaction data.

Experimental Setup

The researchers evaluated GraphRouter using a comprehensive multi-task interaction dataset built from diverse benchmarks:

  • Alpaca: Hybrid QA and Instruction following.
  • GSM8K: Grade school math word problems (Reasoning).
  • SQuAD: Reading comprehension.
  • Multi-News: Multi-document summarization.
  • Extended Set: Later tests included HumanEval (Coding) and HotpotQA (Multi-hop QA).

The system was tested against a pool of 10 to 14 different LLMs, including various parameter sizes of LLaMA, Mixtral, Mistral, and Qwen.

Key Findings and Results

  • Superior Routing Performance: GraphRouter outperformed the strongest baseline routers (such as FrugalGPT and Hybrid LLM) by at least 12.3% in terms of "Reward," a metric that balances response quality with computational cost.
  • Zero-Shot Generalization: In dynamic scenarios where new LLMs were introduced during testing, GraphRouter provided a 9.5% boost in effectiveness compared to baseline methods.
  • Massive Efficiency Gains: Because it is an inductive framework, GraphRouter avoids the massive computational overhead of retraining. In "new LLM" settings, it reduced time costs by over 99% compared to transductive methods that require full retraining to incorporate new models.
  • Proximity to Oracle: GraphRouter achieved at least 88.89% of the performance of a theoretical "Oracle" (a perfect router with future knowledge of all model outputs).
  • Small Models Can Punch Up: The graph approach highlighted that smaller models occasionally outperform larger ones on specific queries. A router that only looks at model size misses these "efficiency goldmines," whereas GraphRouter successfully identifies them.

Limitations and Future Directions

While GraphRouter represents a significant step forward, the authors note a few areas for future improvement. Currently, the GNN primarily looks at direct neighbors. Exploring longer paths in the graph (e.g., tracing model "family trees" like LLaMA-2 to LLaMA-3) could further improve routing accuracy.

Additionally, the current framework focuses solely on selecting the model. Future iterations could jointly route a query to both a specific model and an optimal prompting strategy (like Chain-of-Thought). Finally, while the model uses text descriptions effectively, LLMs still struggle to perfectly process numerical differences in token pricing or context lengths, making numerical sensitivity an area for ongoing refinement.

Summary updated

BibTeX
@inproceedings{feng2025graphrouter,
  author = {Tao Feng and Yanzhen Shen and Jiaxuan You},
  title = {{GraphRouter: A Graph-based Router for LLM Selections}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=eU39PDsZtT},
}
Figure