Route a question to a different AI model
Create an AI agent workflow that routes a question to a different AI model depending on its complexity
Overview
Routing is a workflow pattern that classifies an input and directs it to a specialized followup task. This pattern allows for separation of concerns and building more specialized prompts, which is particularly effective when there are distinct categories that are better handled separately. Without routing, optimizing for one kind of input can hurt performance on other inputs.
Example task
In this example, we’ll create a workflow that routes a question to a different AI model depending on its complexity. This approach is particularly effective when tasks require different models or approaches for different inputs.
This task:
- Uses
generateText
from Vercel’s AI SDK to interact with OpenAI models - Uses
experimental_telemetry
in the source verification and historical analysis tasks to provide LLM logs - Routes questions using a lightweight model (
o1-mini
) to classify complexity - Directs simple questions to
gpt-4o
and complex ones togpt-o3-mini
- Returns both the answer and metadata about the routing decision
Run a test
Triggering our task with a simple question shows it routing to the gpt-4o model and returning the answer with reasoning: