This blog is part of the ADK Masterclass - Hands-On Series. We've covered built-in tools, custom functions, and OpenAPI capabilities. Now, it's time to bring it all together.
A Multi-Tool Agent is an agent empowered with a diverse set of tools. It can dynamically decide which tool (or combination of tools) is best suited to solve a user's problem.
View Code on GitHubTable of Contents
1. What is a Multi-Tool Agent?
When we provide an agent with multiple tools, we are essentially giving it a toolbox. The LLM's reasoning engine evaluates the user's request against the descriptions of all available tools and decides which one(s) to use.
For example, if a user asks: "What's the weather in Tokyo and what time is it there?", the agent understands it needs to:
- Use a Search Tool to find current weather information.
- Use a Time Tool to get the current time in Tokyo.
- Combine both results into a coherent response.
Key benefits of Multi-Tool Agents:
- Versatility: Handle a wide variety of user requests with a single agent.
- Automatic Routing: The LLM decides which tool to use based on context.
- Composability: Combine built-in tools, custom functions, and sub-agents.
- Multi-Step Reasoning: Chain tool calls to solve complex problems.
2. Tutorial
Building a Super Assistant
We will build an agent that combines Google Search (via a sub-agent), Python code execution (via a sub-agent), and a custom timezone function.
Prerequisites
- Python 3.11 or higher
- Google API key from AI Studio
- ADK installed (
pip install google-adk)
Step 1: Create the Project
Initialize a new agent project:
adk create super_assistant
cd super_assistant
Set up environment variables:
cp .env.example .env
# Edit .env and add our GOOGLE_API_KEY
Install additional dependencies:
pip install pytz
Step 2: Define the Agent
Open agent.py and replace its content with the following code:
from google.adk.agents import Agent
from google.adk.tools import google_search
from google.adk.tools.agent_tool import AgentTool
from google.adk.code_executors import BuiltInCodeExecutor
# 1. Define a custom function tool
def get_local_time(timezone: str) -> dict:
"""
Returns current time for a given timezone.
Args:
timezone (str): The timezone name (e.g., 'America/New_York', 'Asia/Tokyo').
Returns:
dict: Current time in the specified timezone.
"""
from datetime import datetime
import pytz
try:
tz = pytz.timezone(timezone)
current_time = datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
return {"status": "success", "timezone": timezone, "current_time": current_time}
except Exception as e:
return {"status": "error", "message": f"Invalid timezone: {timezone}"}
# 2. Create specialized sub-agents for built-in tools
search_agent = Agent(
model='gemini-2.5-flash',
name='SearchAgent',
instruction="You are a specialist in web search. Use Google Search to find information.",
tools=[google_search],
)
code_agent = Agent(
model='gemini-2.5-flash',
name='CodeAgent',
instruction="You are a specialist in code execution. Write and run Python code for calculations.",
code_executor=BuiltInCodeExecutor(),
)
# 3. Create the Multi-Tool Agent using AgentTool
root_agent = Agent(
model='gemini-2.5-flash',
name='SuperAssistant',
instruction="""
You are a versatile assistant with access to multiple capabilities:
- Use SearchAgent for real-time web information (news, weather, facts).
- Use CodeAgent for complex math, data analysis, or code execution.
- Use get_local_time for timezone queries.
Analyze the user's request and choose the appropriate tool(s).
You can use multiple tools in sequence if needed.
""",
tools=[AgentTool(agent=search_agent), AgentTool(agent=code_agent), get_local_time],
)
Step 3: Run the Agent
Start the agent:
adk web
Try these example queries:
- "What's the current time in Tokyo?"
- "Search for the latest news about AI agents."
- "Calculate the compound interest on $10,000 at 5% for 10 years."
- "What's the weather in London and what time is it there?"
3. How it Works
The beauty of ADK is that the orchestration is handled automatically. When a user asks a complex question, the agent:
- Analyzes the request and identifies which tools are needed.
- Calls the appropriate tool(s) - sometimes in sequence.
- Observes the output from each tool call.
- Synthesizes all the information into a final, coherent answer.
Why Use AgentTool?
We use AgentTool to wrap our sub-agents (SearchAgent, CodeAgent) because:
- Isolation: Each sub-agent has its own specialized instruction and tools.
- Flexibility: The parent agent can delegate tasks to the most appropriate sub-agent.
- Scalability: We can add more specialized agents without changing the parent agent's code.
Tool Selection
The LLM uses the tool descriptions to make intelligent decisions. That's why clear, descriptive docstrings and instructions are crucial:
- The
get_local_timefunction has a docstring explaining what it does. - Each sub-agent has an
instructionthat describes its specialty. - The parent agent's instruction explains when to use each tool.
Next Steps
Extend our agents further:
- Third Party Tools: Connect our agents to external services like GitHub and Firecrawl using MCP.