Intelligent task routing based on content analysis, user intent, and dynamic conditions.
from mcp_agent.app import MCPApp from mcp_agent.agents.agent import Agent from mcp_agent.workflows.router.router_llm import OpenAILLMRouter app = MCPApp(name="router_example") async with app.run() as context: # Create specialized agents finder_agent = Agent( name="finder", instruction="Find and retrieve information from files and URLs.", server_names=["fetch", "filesystem"] ) writer_agent = Agent( name="writer", instruction="Create and modify files on the filesystem.", server_names=["filesystem"] ) reasoning_agent = Agent( name="reasoner", instruction="General knowledge and reasoning tasks.", server_names=[] ) # Create router with multiple options router = OpenAILLMRouter( agents=[finder_agent, writer_agent, reasoning_agent], functions=[print_to_console, print_hello_world], ) # Route request to best agent results = await router.route_to_agent( request="Print the contents of mcp_agent.config.yaml verbatim", top_k=1 ) # Use the selected agent selected_agent = results[0].result async with selected_agent: llm = await selected_agent.attach_llm(OpenAIAugmentedLLM) result = await llm.generate_str("Print the config file contents")