Overview
TheMultiAgentRouter uses a boss agent powered by LLMs to intelligently route tasks to the most appropriate specialized agent(s). The boss agent analyzes task requirements and agent capabilities to make routing decisions, supporting both single and multiple agent assignments.
Installation
Attributes
Unique identifier for the router instance. When left as
None, resolves to generate_id("multi-agent-router")The temperature for the boss agent’s model. Unset sends none, which current Claude models require
LiteLLM instance that backs the boss agent (router.function_caller).
Methods
route_task()
Routes a task to the appropriate agent(s) and returns their response.task(str): The task to be routed
output_type), containing the user task and the response(s) that were appended to it.
When the boss selects multiple agents,
handle_multiple_handoffs() runs all of them concurrently but only appends the first selected agent’s response to the conversation — every other agent’s output is computed and then discarded. The boss’s reasoning is never added to the conversation either (it is only printed to the console when print_on=True), so it is not present in the returned result.run()
Alias forroute_task(). Each call is recorded as a MultiAgentRouter.run trace span when telemetry is enabled. Calling the router directly, router(task), does the same thing.
batch_run()
Batch route tasks to the appropriate agents sequentially.tasks(List[str]): List of tasks to route
concurrent_batch_run()
Concurrently route tasks to the appropriate agents.tasks(List[str]): List of tasks to route
Usage Examples
Basic Routing
Custom System Prompt
Batch Processing
Multiple Agent Assignment
Skip Null Tasks
Response Format
The boss agent returns routing decisions in this JSON format:Features
- Intelligent Routing: Boss agent analyzes task requirements and agent capabilities
- Single or Multiple Agents: Automatically determines if task requires one or multiple agents
- Custom Routing Logic: Override system prompt to customize routing behavior
- Batch Processing: Process multiple tasks sequentially or concurrently
- Flexible Output: Support for various output formats (dict, string, json, etc.)
- Null Task Handling: Option to skip agents with null/empty task assignments