contributing/agent_samples/sub_agents/README.md
This sample demonstrates how to create a hierarchical agent setup using sub-agents in the ADK framework, and also showcases how to use tool confirmation.
It defines a root Agent named sub_agents that coordinates two sub-agents: info_agent and close_agent.
info_agent is equipped with a tool to check account status.close_agent is equipped with a tool to close accounts, which requires user confirmation before execution.The root agent delegates tasks to these sub-agents based on the user's prompt. This sample illustrates how to modularize capabilities into separate agents instead of combining all tools on a single agent.
Check the status of account ACC-123.Close account ACC-123.Check if account ACC-123 is active, and if so, close it.Agent (name="sub_agents")
├── Agent (name="info_agent")
│ └── Tool (name="get_account_status")
└── Agent (name="close_agent")
└── Tool (name="close_account", require_confirmation=True)
Define the specific tools for each sub-agent:
def get_account_status(account_id: str) -> str:
"""Gets the status of a bank account."""
return f"Account {account_id} is active."
def close_account(account_id: str) -> str:
"""Closes a bank account."""
return f"Account {account_id} has been closed."
Register tools to their respective sub-agents, using FunctionTool for confirmation:
from google.adk.agents import Agent
from google.adk.tools.function_tool import FunctionTool
info_agent = Agent(
name="info_agent",
description="An agent that can check account status.",
tools=[get_account_status],
)
close_agent = Agent(
name="close_agent",
description="An agent that can close accounts.",
tools=[FunctionTool(func=close_account, require_confirmation=True)],
)
Add the sub-agents to the root agent's sub_agents list:
root_agent = Agent(
name="sub_agents",
sub_agents=[info_agent, close_agent],
)