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
generateObjectfrom the AI SDK to classify the question into a typed routing decision - Uses
experimental_telemetryto surface each LLM call on the Run page in the dashboard - Classifies complexity with a fast, cheap model (
claude-haiku-4-5) - Directs simple questions to
claude-haiku-4-5and complex ones toclaude-sonnet-4-5 - Returns both the answer and metadata about the routing decision
Run a test
Triggering our task with a simple question shows it routing to theclaude-haiku-4-5 model and returning the answer with reasoning:

