Autogen Agents Routing
AutoGen Routing Agent
In this tutorial, we'll explore Routing agent workflows using AutoGen's function calling capabilities and agent interactions to direct tasks efficiently.
Agent Routing is a pattern designed to handle incoming requests by classifying them and directing them to the single most appropriate specialized agent or workflow. This ensures requests are immediately handled by the correct specialist, improving efficiency.
AutoGen simplifies implementing this pattern by enabling a dedicated 'Router Agent' to analyze incoming messages and use function calls to signal its classification decision. Based on this classification, the workflow explicitly directs the query to the appropriate specialist agent for a focused, separate interaction.
With Phoenix tracing, you get full visibility into this process, clearly seeing the router's classification, the function call made, and the subsequent handoff to the specialist.
By the end of this tutorial, you’ll learn how to:
- Define AutoGen agents with specific tools (functions).
- Create a dedicated Router Agent for request classification.
- Implement a workflow that routes requests to specialist agents based on classification.
- Trace and visualize the routing process and agent interactions using Phoenix.
⚠️ You'll need an OpenAI Key for this tutorial.
Set up Keys and Dependencies
Configure Tracing
Example Routing Task: Customer Support Agent
We will build an intelligent customer service system, designed to efficiently handle diverse user queries by leveraging specialized agents. We use tracing to tackle the common challenge of ensuring incoming requests are promptly routed to the appropriate agent.
Below is a high-level diagram of our setup. Specifically, a dedicated router agent analyzes the user's initial message solely to classify its topic, triggering a handoff. A specialized agent then uses its tools to address the query. Once a termination condition is reached, the user gets an output.

Define Agent
The llm_config specifies the configuration used for each AssistantAgent.
This cell defines functions that simulate typical operations for a customer support scenario, such as retrieving user subscription data, checking payment history, verifying server status, and handling account actions like password resets. In a real setting, we would use data retrieval techniques.
These functions will act as the tools for our agents.
Next, we define three AutoGen AssistantAgent instances, each specialized for a specific customer support function: Billing, Technical support, and Account Management.
Each agent is given a unique system message describing its role, and its llm_config includes schemas for only the specific function-calling tools relevant to its domain.
This section defines two helper functions:
route_to_specialistgets the topic classification decision made by a router LLM into a global variablecheck_for_termination_messageidentifies if a message signals the end of the chat.
Then, we initialize the main AutoGen UserProxyAgent and configuring it to use these functions for termination checks and equipping it to execute any of the tool functions when called by an AssisstantAgent. The UserProxyAgent also acts as the human user within the AutoGen framework, initiating conversations and managing user interaction.
Finally, we define our router. This AssistantAgent classifies incoming customer support requests into categories: billing, technical, account, or unknown.
The system message instructs the router_agent not to answer queries directly, but instead to analyze the request and call the specific route_to_specialist function.
Run Agent
We are now ready to run our agent. First, the user will be prompted for their query. Then there is an interaction between the UserProxyAgent and the router_agent to classify the request's topic.
Based on the classification result captured from the first interaction, it either initiates a separate, follow-up chat with the appropriate AssisstantAgent or provides feedback to the user if routing was unsuccessful.
View Results in Phoenix
In Phoenix, we unlock observability into our agent's operations and decision-making process. The traces allow easy inspection of foundational elements like system prompts and function call. Phoenix also showcases the reasoning behind routing choices and provides transparency into tool interactions by tracking both input parameters and generated outputs.
Run the cell below to see the full tracing results.