Routing & Classification

Pattern

Agent Routing Pattern

Route user queries to specialized AI agents based on context and intent. Includes dynamic agent selection, load balancing, and fallback handling.

IntermediateOct 2025View the full pattern on desktop
Agent Routing Pattern preview

Problems solved

  • Classify support queries into specialized agent categories
  • Route each query to a tailored agent system prompt
  • Select models by query complexity before streaming a reply
  • Stream classification metadata to the client as custom data parts
  • Fall back across OpenAI, Perplexity, and Deepseek providers

Use cases

  • Customer support desks that route by intent
  • Multi-department help centers
  • Sales and billing inquiry triage
  • Technical support chat with specialist agents
  • Intent-based agent orchestration demos

AI SDK APIs

generateObjectstreamTextconvertToModelMessagesnew Agenttool(stepCountIs

Tags

aiagentsroutingai-sdk

Requirements

Node.js
24+
Memory
512MB
Other
  • OpenAI API key
  • Perplexity API key (optional)
  • Deepseek API key (optional)

Environment variables

External services

openaiperplexitydeepseek

Ready to use?

View the full interactive pattern with live preview and copy the source code.

View the pattern on desktop

Related patterns