|
|
ADK Built-in Tools - Google Search and Code Execution
Author: Venkata Sudhakar
ADK ships with two powerful built-in tools that give agents capabilities far beyond text generation: google_search grounds responses in live web data, and code_execution lets the agent write and run Python code to solve problems programmatically. These are not custom tools you build - they are pre-integrated capabilities you add to any ADK agent with one line. An agent with google_search can answer questions about current events, live prices, or recent news. An agent with code_execution can write Python, run it in a secure sandbox, see the output, and iterate - turning vague analytical questions into precise computed answers. You add built-in tools by importing them from google.adk.tools and including them in the agent tools list alongside your custom Python functions. The agent autonomously decides when to search the web versus when to write code versus when to use a custom tool - you just declare what is available. A sales analyst agent with all three can search for current commodity prices (google_search), load and analyse your sales CSV (code_execution), and query your order database (custom tool) - all in a single conversation turn, calling whichever tool is appropriate for each part of the question. The below example builds a sales intelligence agent that combines Google Search for live market data with code execution for data analysis - giving a business analyst real-time, computed answers rather than estimates.
Running three types of queries showing different tool combinations,
It gives the following output showing different tools being used per query,
Q1: Calculate Q1 2025 revenue trend and growth rates
[Agent calls: get_monthly_sales x3, then code_execution]
Python executed:
data = {"Jan": 4250000, "Feb": 3890000, "Mar": 5120000}
months = list(data.keys())
for i in range(1, len(months)):
prev = data[months[i-1]]
curr = data[months[i]]
growth = round((curr - prev) / prev * 100, 1)
print(months[i], "growth:", growth, "%")
print("Q1 Total:", sum(data.values()))
Output:
Feb growth: -8.5%
Mar growth: +31.6%
Q1 Total: 13260000
ANALYSIS: Q1 2025 total revenue was Rs 1.33 crore. February dipped 8.5% from
January but March surged 31.6%, likely driven by financial year-end purchases.
Strong recovery makes Q1 overall healthy despite the Feb dip.
Q2: May performance vs industry summer season
[Agent calls: get_monthly_sales, then google_search]
Our May data: Rs 62.3L revenue, 1,287 units, top product Air Conditioner, 14% margin.
[Searched: India electronics sales May 2025 summer AC season]
Industry context: India AC market grew 38% in April-May 2025 summer season.
Our AC-led May performance aligns with this industry trend. Our unit growth
(1,287 vs April 967 = +33%) is slightly below the 38% industry average,
suggesting some market share opportunity remaining in the AC category.
# Q1: Used internal tool + code execution to compute exact numbers
# Q2: Used internal tool + google_search to benchmark against live industry data
# Agent chose the right tools autonomously for each part of the question
Built-in tool best practices: give the agent a clear instruction about when to use each tool type so it does not search the web for data you have internally. Code execution is sandboxed - the agent cannot access your filesystem or network from within the code execution environment, only the data it passes in as variables. For sensitive internal data, pass it as a string or JSON into the code execution context via the custom tool rather than having the agent search for it externally. Combine all three tool types for the most powerful analyst agents: custom tools for your proprietary data, google_search for current external context, and code_execution for precise computation on the combined dataset.
|
|