Minimal Example
research_team.py
Team Modes
Teams default to coordinate mode (leader delegates and synthesizes). Setmode to change how the leader collaborates with members.
| Mode | Configuration | Use case |
|---|---|---|
| Coordinate | mode=TeamMode.coordinate (default) | Decompose work, delegate to members, synthesize results |
| Route | mode=TeamMode.route | Route to a single specialist and return their response directly |
| Broadcast | mode=TeamMode.broadcast | Delegate the same task to all members and synthesize |
| Tasks | mode=TeamMode.tasks | Run a task list loop until the goal is complete |
max_iterations to cap how many cycles the leader can run.
Team Members
Each member should have aname and role. The team leader uses these to decide who handles what.
id:
id and name are set on a member, team delegation uses id as the member identifier.
Nested Teams
Teams can contain other teams. The top-level leader delegates to sub-team leaders, who delegate to their members.Model Inheritance
Team members inherit themodel from their parent team if not explicitly set.
Callable Factories
Pass a function instead of a static list formembers, tools, or knowledge. The function is called at the start of each run, so the composition can vary per user or session.
team_callable_members.py
tools and knowledge. Agents also support callable factories for tools and knowledge.
Injected Parameters
Name your factory function parameters to receive context automatically:| Parameter | Type | Description |
|---|---|---|
agent | Agent | The current Agent instance |
team | Team | The current Team instance |
run_context | RunContext | Run context with user_id, session_id, session_state |
session_state | dict | Session state dict directly (defaults to {} if None) |
add_tool and set_tools
add_tool() raises RuntimeError when tools is a callable factory. Use set_tools() to replace the factory entirely:
Callable Caching Settings
Factory results are cached by default. The cache key is resolved in this order: custom key function >user_id > session_id. If none are available, caching is skipped and the factory runs every time.
| Setting | Default | Description |
|---|---|---|
cache_callables | True | Enable or disable caching for all callable factories |
callable_tools_cache_key | None | Custom cache key function for tools factory |
callable_knowledge_cache_key | None | Custom cache key function for knowledge factory |
callable_members_cache_key | None | Custom cache key function for members factory (Team only) |
cache_callables=False when session_state changes between runs and the factory should re-evaluate each time.
Clear cached results programmatically:
aclear_callable_cache() in async code.
Team Features
Teams support the same features as agents:| Feature | Description |
|---|---|
| Instructions | Guide the team leader on how to coordinate |
| Mode | Choose the coordination strategy (coordinate, route, broadcast, tasks) |
| Database | Persist session history and state |
| Reasoning | Enable the leader to plan before delegating |
| Knowledge | Give the leader access to a knowledge base |
| Memory | Store and recall information across sessions |
| Tools | Give the leader tools to use directly |
Next Steps
| Task | Guide |
|---|---|
| Run teams | Running Teams |
| Control delegation | Delegation |
| Add chat history | Chat History |
| Manage sessions | Sessions |
| Handle input/output | Input and Output |
| Add knowledge | Knowledge |
| Add guardrails | Guardrails |