Skip to main content
Experimental FeatureThis feature is currently experimental and the API may change. If you encounter any issues, please provide feedback via GitHub Issues.

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:
  1. Creates Sub-agent Instance: Creates a new agent instance via the Provider factory
  2. Restores Conversation State: If session_id is provided, restores previous state from Session
  3. Executes Conversation: Sub-agent processes the message and generates a response
  4. Saves State: Saves sub-agent state to Session for future calls
  5. Returns Result: Returns the response and session_id to the parent agent

Quick Start

Configuration Options

Customize sub-agent tool behavior with SubAgentConfig:

Multi-turn Conversation

Sub-agents support multi-turn conversations, maintaining state via the session_id parameter:
The sub-agent tool exposes two parameters:
  • message (required): Message to send to the sub-agent
  • session_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:

Tool Group Support

Sub-agent tools can be added to tool groups like regular tools: