7. Built-in Tools - Google Search, Code Executor

This blog is part of the ADK Masterclass - Hands-On Series. In this post, we'll explore Built-in Tools, which are ready-to-use capabilities that come pre-packaged with the Agent Development Kit.

Tools are the hands and eyes of an agent. While an LLM can reason, it cannot inherently access the internet, execute code, or query a database. Tools bridge this gap, allowing agents to perform actions in the real world.

View Code on GitHub

Table of Contents

1. What is Built-in Tools?

Built-in tools deliver instant capabilities with zero setup required. Designed specifically for the ADK ecosystem, they come pre-configured with robust error handling and authentication, allowing us to focus on building our agent's logic rather than boilerplate code.

Common built-in tools include:

  • Google Search: For retrieving real-time information from the web.
  • Code Execution: For performing mathematical calculations or data analysis.
  • Google Cloud Services: Integrations with BigQuery, Vertex AI Search, and more.

2. Google Search Tool

graph LR User[User Query] --> Agent[Agent] Agent -->|Calls Tool| Search[Google Search Tool] Search -->|API Request| Google[Google Search Engine] Google -->|Results| Search Search -->|Snippets| Agent Agent -->|Answer| User style Agent fill:#e3f2fd,stroke:#1565c0,stroke-width:2px style Search fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px style Google fill:#fff9c4,stroke:#fbc02d,stroke-width:2px

The google_search tool connects our agent to the world's information. This is crucial for answering questions about current events, checking facts, or finding specific data points that aren't in the model's training data.

Use cases:

  • "What is the stock price of Google today?"
  • "Who won the latest Super Bowl?"
  • "Find recent news about AI regulations."

3. Code Execution Tool

graph LR User[User Query] --> Agent[Agent] Agent -->|Generates Code| Executor[Code Execution Tool] Executor -->|Runs Code| Sandbox[Python Sandbox] Sandbox -->|Output/Error| Executor Executor -->|Result| Agent Agent -->|Final Answer| User style Agent fill:#e3f2fd,stroke:#1565c0,stroke-width:2px style Executor fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px style Sandbox fill:#fff9c4,stroke:#fbc02d,stroke-width:2px

LLMs are great at language but can struggle with complex math or logic puzzles. The BuiltInCodeExecutor allows the agent to write Python code, execute it in a secure sandbox, and use the output as part of its answer.

Use cases:

  • "Calculate the 100th Fibonacci number."
  • "Analyze this dataset and find the average revenue."
  • "Plot a graph of this function."

4. Tutorial

Let's build a simple agent that uses Google Search to answer questions. We'll set this up using the ADK CLI.

Prerequisites

  • Python 3.11 or higher
  • Google API Key (from AI Studio)

Step 1: Create the Project

Use the ADK CLI to create a new agent project:

adk create google_search_agent
cd google_search_agent

Set up our environment variables:

cp .env.example .env
# Edit .env and add our GOOGLE_API_KEY

Step 2: Modify the Agent

Open agent.py and replace its content with the following code to enable the Google Search tool:

from google.adk.agents import Agent
from google.adk.tools import google_search

root_agent = Agent(
    model="gemini-2.5-flash",
    name="google_search_agent",
    instruction="You are a helpful assistant that can search the web for information.",
    tools=[google_search],
)

Step 3: Run the Agent

Run our agent using the ADK web interface:

adk web

Visit the URL shown in your terminal (typically http://localhost:8000) to chat with our agent. Try asking: "What is the latest news about Gemini?"

4.2. Building a Code Execution Agent

Now, let's create an agent that can write and run code.

This enables use cases like:

  • "Calculate the 100th Fibonacci number."
  • "Analyze this dataset and find the average revenue."
  • "Plot a graph of this function."

Step 1: Create the Project

adk create math_agent
cd math_agent

Step 2: Define the Agent

Update agent.py with the code execution configuration:

from google.adk.agents import Agent
from google.adk.code_executors import BuiltInCodeExecutor

math_agent = Agent(
    model='gemini-2.5-flash',
    name='MathAgent',
    instruction="You are a mathematician. Write and execute Python code to solve complex problems.",
    code_executor=BuiltInCodeExecutor()
)

In the next section, we'll look at how to integrate Third Party Tools like GitHub to extend our agent's capabilities even further.

Next Steps

Now that we've covered basic built-in tools, let's explore enterprise data capabilities:

Resources

Comments