Skip to main content
Based on Anthropic’s “Building Effective Agents” framework. Routing directs different types of requests to specialized handlers optimized for specific domains. A classification step determines the request type, then routes it to the appropriate specialized agent or tool. This pattern improves response quality by using domain-specific prompts and context while maintaining a single entry point for users.
Client
Router Agent
Classification
Support Handler
Sales Handler
request
classify
category
route to handler
specialized response
response

When to Use

Use routing when you have distinct request types that benefit from specialized handling, such as customer service systems with support, sales, and billing inquiries. It’s ideal when different domains require different prompts, tools, or context. Avoid routing when requests are too similar to benefit from specialization or when the classification overhead outweighs the benefits of specialized handling.

Implementation

This example demonstrates a customer service router that classifies incoming messages as Support, Sales, or Other requests, then directs them to specialized handlers optimized for each domain.

Agent Code

This tool uses structured output to ensure reliable classification into predefined categories. The LLM analyzes the message content and returns a valid enum value, preventing invalid classifications that could break the routing logic.
This specialized handler focuses on technical support scenarios, using domain-specific prompts and suggesting common troubleshooting steps. The context is optimized for support interactions rather than general conversation.
This handler specializes in sales conversations, including specific product information like pricing ($42) in the context. The prompt is optimized for sales scenarios rather than technical support, providing more relevant responses for commercial inquiries.
The pattern uses a two-step process: classification determines the request type, then specialized handlers provide domain-optimized responses. Each handler uses prompts and context tailored to its specific domain, improving response quality compared to a general-purpose agent. The canHelp boolean indicates whether the system can assist with the request. This pattern complements prompt chaining for complex multi-step workflows and can be combined with parallelization when multiple handlers need to process the same request simultaneously.