Overview
Agent as Tool allows registering an agent as a tool that can be called by other agents. This pattern is useful for building hierarchical or collaborative multi-agent systems:- Expert Specialization: Main agent calls different expert agents based on task type
- Task Delegation: Delegate complex subtasks to specialized agents
- Multi-turn Conversation: Sub-agents can maintain conversation state for continuous interaction
How It Works
When a parent agent calls a sub-agent tool, the system:- Creates Sub-agent Instance: Creates a new agent instance via the Provider factory
- Restores Conversation State: If
session_idis provided, restores previous state from Session - Executes Conversation: Sub-agent processes the message and generates a response
- Saves State: Saves sub-agent state to Session for future calls
- Returns Result: Returns the response and
session_idto the parent agent
Quick Start
Configuration Options
Customize sub-agent tool behavior withSubAgentConfig:
Multi-turn Conversation
Sub-agents support multi-turn conversations, maintaining state via thesession_id parameter:
message(required): Message to send to the sub-agentsession_id(optional): Session ID. Omit to start new session, provide to continue existing one
Persistent Sessions
By default,InMemorySession is used and state is lost on process restart. Use JsonSession to persist state to files: