What You’ll Learn
- How to create multiple agents with different roles
- How to use AgentTool to wrap agents as tools
- How to orchestrate agent-to-agent communication
Prerequisites
Code Example
This example creates two expert agents (math and chemistry) that can be consulted by a main assistant:Run the Example
Expected Output
For the math question:How It Works
- Specialized Agents: Creates two expert agents with specific system messages
- AgentTool: Wraps each expert agent as a tool that can be called by the main assistant
- Tool Selection: The main assistant automatically determines which expert to consult
- Streaming: Uses streaming for real-time output display
Key Concepts
AgentTool
Wraps an agent as a tool that can be called by another agent.
System Message
Defines the agent’s role, personality, and capabilities.
Tool Selection
The LLM automatically decides which tool/agent to use based on the task.
Streaming
Display responses in real-time as they’re generated.
Configuration Options
AgentTool Parameters
return_value_as_last_message: Returns only the final message from the agent (cleaner output)description: Helps the calling agent understand when to use this tool
AssistantAgent Parameters
system_message: Defines the agent’s persona and instructionsmodel_client_stream: Enables streaming responsesmax_tool_iterations: Maximum number of tool calls allowed
Next Steps
Tool Calling
Learn how to add custom tools to agents
Swarm Pattern
Implement more complex multi-agent orchestration