Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
agents | list[Any] | Required | List of Agent instances to use as team members |
tasks | list[Task] | None | None | List of tasks to execute (optional) |
model | Optional[Any] | None | The model provider instance for any internal agents (leader, router). Required for ‘coordinate’ and ‘route’ modes |
response_format | Any | str | The response format for the end task (optional) |
ask_other_team_members | bool | False | A flag to automatically add other agents as tools to each task. When True, add_tool() is called during initialization |
mode | Literal["sequential", "coordinate", "route"] | "sequential" | The operational mode for the team (‘sequential’, ‘coordinate’, or ‘route’) |
memory | Optional[Memory] | None | Memory instance for team operations. In sequential mode, if provided, it will be shared with all agents that don’t already have memory configured |
debug | bool | False | Enable debug logging |
debug_level | int | 1 | Debug level (1 = standard, 2 = detailed). Only used when debug=True |
Operational Modes
Sequential Mode
Tasks are assigned to agents sequentially based on task-agent matching. The system:- Builds a selection context from current task, all tasks, task index, agents, and previous results
- Selects the best agent for each task using intelligent task assignment
- Enhances task context with information from previous tasks and results
- Executes tasks one by one
- Combines results if multiple tasks are executed (or returns single result if only one task)
memory is provided, it is automatically shared with all agents that don’t already have memory configured.
Result Handling: If multiple tasks are executed, results are combined using a result combiner. If only one task is executed, the single result is returned directly.
Coordinate Mode
A leader agent coordinates task delegation to team members. This mode:- Creates a leader agent with a system prompt containing team roster and mission objectives
- Provides a delegation tool that allows the leader to assign tasks to team members
- The leader agent analyzes the mission and delegates tasks to appropriate team members
- Team members execute delegated tasks with shared memory context
- Returns the final response from the leader agent
modelmust be set (raises ValueError if not provided)- Creates an internal
leader_agent(accessible viateam.leader_agent) - Automatically creates memory if not provided (uses InMemoryStorage with
full_session_memory=True)
Route Mode
A router agent selects the best specialist for the entire request. This mode:- Creates a router agent with a system prompt containing team roster and mission objectives
- Provides a routing tool that allows the router to select a single team member
- The router analyzes the full mission and selects the best specialist
- All tasks are consolidated into a single task with all attachments and tools
- The selected agent executes the consolidated task
- Returns the response from the selected agent
modelmust be set (raises ValueError if not provided)- Creates an internal
leader_agent(accessible viateam.leader_agent)
- Combined descriptions
- All attachments from all tasks
- All unique tools from all tasks
- The specified
response_format
Functions
complete
Execute multi-agent operations with the predefined agents and tasks (alias for do).
Parameters:
tasks(list[Task] | Task | None): Optional list of tasks or single task to execute. If not provided, uses tasks from initialization
- The response from the multi-agent operation
print_complete
Execute the multi-agent operation and print the result (alias for print_do).
Parameters:
tasks(list[Task] | Task | None): Optional list of tasks or single task to execute. If not provided, uses tasks from initialization
- The response from the multi-agent operation
do
Execute multi-agent operations with the predefined agents and tasks. This is the main entry point for team execution.
Parameters:
tasks(list[Task] | Task | None): Optional list of tasks or single task to execute. If not provided, uses tasks from initialization
- The response from the multi-agent operation
multi_agent
Execute multi-agent operations with agent configurations and tasks. This method automatically handles event loop detection - if a loop is already running, it uses run_coroutine_threadsafe, otherwise it creates a new event loop.
Parameters:
agent_configurations(List[Agent]): List of agent configurationstasks(Any): Tasks to execute
- The response from the multi-agent operation
multi_agent_async
Asynchronous version of the multi_agent method. Supports three operational modes:
- sequential: Tasks are assigned to agents sequentially based on task-agent matching. Results are combined if multiple tasks are executed.
- coordinate: A leader agent coordinates task delegation to team members. Requires a
modelto be set. - route: A router agent selects the best specialist for the task. Requires a
modelto be set.
agent_configurations(List[Agent]): List of agent configurationstasks(Any): Tasks to execute
- The response from the multi-agent operation
print_do
Execute the multi-agent operation and print the result.
Parameters:
tasks(list[Task] | Task | None): Optional list of tasks or single task to execute. If not provided, uses tasks from initialization
- The response from the multi-agent operation
add_tool
Add agents as tools to each Task object in self.tasks. This method is automatically called when ask_other_team_members is set to True during initialization.
Behavior:
- Iterates through all tasks in
self.tasks - Adds all team agents to each task’s tools list
- If a task doesn’t have a
toolsattribute, it creates an empty list first - If
toolsis not a list, it replaces it with the agents list
Internal Attributes
leader_agent
An internal Agent instance created for ‘coordinate’ and ‘route’ modes. This is the leader/router agent that manages task delegation or routing. Accessible via team.leader_agent after execution in these modes.
Type: Optional[Agent]
