Skip to main content

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. Routing

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 generateObject from the AI SDK to classify the question into a typed routing decision
  • Uses experimental_telemetry to 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-5 and complex ones to claude-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 the claude-haiku-4-5 model and returning the answer with reasoning: