arrow_back

Empower ADK agents with tools

Sign in Join
Get access to 700+ labs and courses

Empower ADK agents with tools

Lab 1 hour 30 minutes universal_currency_alt 5 Credits show_chart Advanced
info This lab may incorporate AI tools to support your learning.
Get access to 700+ labs and courses

GENAI105

Overview

This lab covers the use of tools with Agent Development Kit agents.

From powerful tools provided by Google, like Google Search and Vertex AI Search, to the rich variety of tools available in the LangChain and CrewAI ecosystems, there are many tools to get started with.

Additionally, creating your own tool from a function only requires writing a good docstring!

This lab assumes you are familiar with the basics of ADK covered in the lab Get started with Agent Development Kit (ADK).

Objective

In this lab, you will learn about the ecosystem of tools available to ADK agents. You will also learn how to provide a function to an agent as a custom tool.

After this lab, you will be able to:

  • Provide prebuilt Google, LangChain, or CrewAI tools to an agent
  • Discuss the importance of structured docstrings and typing when writing functions for agent tools
  • Write your own tool functions for an agent

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Pixelbook, open an Incognito window to run this lab.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details pane.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details pane.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field.

Tool use with the Agent Developer Kit

Leveraging tools effectively is what truly distinguishes intelligent agents from basic models. A tool is a block of code, like a function or a method, that executes specific actions such as interacting with databases, making API requests, or invoking other external services.

Tools empower agents to interact with other systems and perform actions beyond their core reasoning and generation capabilities. It's crucial to note that these tools operate independently of the agent's LLM, meaning that tools do not automatically possess their own reasoning abilities.

Agent Development Kit provides developers with a diverse range of tool options:

  • Pre-built Tools: Ready-to-use functionalities such as Google Search, Code Execution, and Retrieval-Augmented Generation (RAG) tools.
  • Third-Party Tools: Seamless integration of tools from external libraries like LangChain and CrewAI.
  • Custom Tools: The ability to create custom tools tailored to specific requirements, by using language specific constructs and Agents-as-Tools. The SDK also provides asynchronous capabilities through Long Running Function Tools.

In this lab, you will explore these categories and implement one of each type.

Available Pre-Built Tools from Google

Google provides several useful tools for your agents. They include:

Google Search (google_search): Allows the agent to perform web searches using Google Search. You simply add google_search to the agent's tools.

Code Execution (built_in_code_execution): This tool allows the agent to execute code, to perform calculations, data manipulation, or interact with other systems programmatically. You can use the pre-built VertexCodeInterpreter or any code executor that implements the BaseCodeExecutor interface.

Retrieval (retrieval): A package of tools designed to fetch information from various sources.

Vertex AI Search Tool (VertexAiSearchTool): This tool integrates with Google Cloud's Vertex AI Search service to allow the agent to search through your AI Applications data stores.

Task 1. Install ADK and set up your environment

Note: Using an Incognito browser window is recommended for most Qwiklabs to avoid confusion between your Qwiklabs student account and other accounts logged into Google Cloud. If you are using Chrome, the easiest way to accomplish this is to close any Incognito windows, then right click on the **Open Google Cloud console** button at the top of this lab and select **Open link in Incognito window**.

Enable Vertex AI recommended APIs

  1. In this lab environment, the Vertex AI API has been enabled for you. If you were to follow these steps in your own project, you could enable it by navigating to Vertex AI and following the prompt to enable it.

Prepare a Cloud Shell Editor tab

  1. With your Google Cloud console window selected, open Cloud Shell by pressing the G key and then the S key on your keyboard. Alternatively, you can click the Activate Cloud Shell button () in the upper right of the Cloud console.

  2. Click Continue.

  3. When prompted to authorize Cloud Shell, click Authorize.

  4. In the upper right corner of the Cloud Shell Terminal panel, click the Open in new window button .

  5. In the Cloud Shell Terminal, enter the following to open the Cloud Shell Editor to your home directory:

    cloudshell workspace ~
  1. Close any additional tutorial or Gemini panels that appear on the right side of the screen to save more of your window for your code editor.
  2. Throughout the rest of this lab, you can work in this window as your IDE with the Cloud Shell Editor and Cloud Shell Terminal.

Download and install ADK and code samples for this lab

  1. Update your PATH environment variable and install ADK by running the following commands in the Cloud Shell Terminal. Note: You will specify the version to ensure that the version of ADK that you install corresponds to the version used in this lab:

    sudo python3 -m pip install google-adk==1.2.1
  2. Paste the following commands into the Cloud Shell Terminal to copy a file from a Cloud Storage bucket, and unzip it, creating a project directory with code for this lab:

    gcloud storage cp gs://{{{project_0.project_id| YOUR_GCP_PROJECT_ID}}}-bucket/adk_tools.zip . unzip adk_tools.zip
  3. Install additional lab requirements with:

    sudo python3 -m pip install -r adk_tools/requirements.txt

Click Check my progress to verify the objective. Install ADK and set up your environment.

Task 2. Create a data store that will be used to ground responses on your own data

In a later task, you will use the Google-provided Vertex AI Search tool to ground responses on your own data in an AI Applications data store. Since this data store needs a little while to ingest data, you will set it up now, then use it to ground responses on your data in a later task.

Example documents have been uploaded to Cloud Storage for you. They relate to the fictional discovery of a new planet named Persephone. (A fictional planet is used in this case so that the model cannot have learned anything about this planet during its training.)

  1. In your browser tab still showing the Cloud Console, navigate to AI Applications by searching for it at the top of the console.
  2. Select the terms and conditions checkbox and click Continue and Activate the API.
  3. From the left-hand navigation menu, select Data Stores.
  4. Select Create Data Store.
  5. Find the Cloud Storage card and click Select on it.
  6. Select Unstructured documents (PDF, HTML, TXT and more)
  7. For a GCS path, enter -bucket/planet-search-docs.
  8. Click Continue.
  9. Keep the location set to global.
  10. For a data store name, enter Planet Search.
  11. Click Create.
  12. Once your data store is created, copy its ID which you will find in the Data Stores table. Save it in a text document as you will need it later.

Click Check my progress to verify the objective. Create a data store.

Third-Party Tools

ADK allows you to use tools available from third-party AI libraries like LangChain and CrewAI.

Task 3. Use a LangChain Tool

The LangChain community has created a large number of tool integrations to access many sources of data, integrate with various web products, and accomplish many things. Using community tools within ADK can save you rewriting a tool that someone has already created.

  1. Back in your browser tab displaying the Cloud Shell Editor, use the file explorer on the left-hand side to navigate to the directory adk_tools/langchain_tool_agent.

  2. Write a .env file to provide authentication details for this agent directory by running the following in the Cloud Shell Terminal:

    cd ~/adk_tools cat << EOF > langchain_tool_agent/.env GOOGLE_GENAI_USE_VERTEXAI=TRUE GOOGLE_CLOUD_PROJECT={{{project_0.project_id| YOUR_GCP_PROJECT_ID}}} GOOGLE_CLOUD_LOCATION={{{project_0.default_region| GCP_LOCATION}}} MODEL=gemini-2.0-flash-001 EOF
  3. Copy the .env file to the other agent directories you will use in this lab by running the following:

    cp langchain_tool_agent/.env crewai_tool_agent/.env cp langchain_tool_agent/.env function_tool_agent/.env cp langchain_tool_agent/.env vertexai_search_tool_agent/.env
  4. Click on the agent.py file in the langchain_tool_agent directory.

  5. Notice the import of the LangchainTool class. This is a wrapper class that allows you to use LangChain tools within Agent Development Kit.

  6. Add the following code where indicated in the agent.py file to add the LangChain Wikipedia tool to your agent. This will allow your agent to search for information on Wikipedia:

    tools = [ # Use the LangchainTool wrapper... LangchainTool( # to pass in a LangChain tool. # In this case, the WikipediaQueryRun tool, # which requires the WikipediaAPIWrapper as # part of the tool. tool=WikipediaQueryRun( api_wrapper=WikipediaAPIWrapper() ) ) ]
  7. Save the file.

  8. In the Cloud Shell Terminal, from the adk_tools project directory, launch the Agent Development Kit Dev UI with the following commands:

    adk web

    Output

    INFO: Started server process [2434] INFO: Waiting for application startup. +-------------------------------------------------------+ | ADK Web Server started | | | | For local testing, access at http://localhost:8000. | +-------------------------------------------------------+ INFO: Application startup complete. INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
  9. To view the web interface in a new tab, click the http://127.0.0.1:8000 link in the Terminal output.

  10. A new browser tab will open with the ADK Dev UI.

  11. From the Select an agent dropdown on the left, select the langchain_tool_agent from the dropdown.

  12. Query the agent with:

    Who was Grace Hopper?

    Output:

  13. Click the agent icon next to the agent's chat bubble indicating the use of the wikipedia tool.

  14. Notice that the content includes a functionCall with the query to Wikipedia.

  15. At the top of the tab, click the forward button to move to the next event.

  16. On the Request tab, you can see the result retrieved from Wikipedia used to generate the model's response.

  17. When you are finished asking questions of this agent, close the dev UI browser tab.

  18. In the Terminal, press CTRL + C to stop the server.

Click Check my progress to verify the objective. Use a LangChain Tool.

Task 4. Use a CrewAI Tool

You can similarly use CrewAI Tools, using a CrewaiTool wrapper.

  1. To do so, using the Cloud Shell Editor file explorer, navigate to the directory adk_tools/crewai_tool_agent.

  2. Click on the agent.py file in the crewai_tool_agent directory.

  3. Notice the import of the CrewaiTool class from ADK and the FileWriterTool from crewai_tools.

  4. Add the following code where indicated in the agent.py file to add the CrewAI File Write tool to your agent, along with a name and description:

    tools = [CrewaiTool( name="file_writer_tool", description=( "Writes a file to disk when run with a" "filename, content, overwrite set to 'true'," "and an optional directory" ), tool=FileWriterTool() )]
  5. Save the file.

  6. You'll run this agent using the command line interface to be familiar with it as a convenient way to test an agent quickly. In the Cloud Shell Terminal, from the adk_tools project directory, launch the agent with the ADK command line UI with:

    adk run crewai_tool_agent
  7. While the agent loads, it may display some warnings. You can ignore these. When you are presented the user: prompt, enter:

    Write a poem about being part of a crew, and save it as a new file crew_poem.txt

    Output:

    Using Tool: File Writer Tool [crewai_tool_agent]: I've saved the poem to crew_poem.txt. Let me know if you need anything else.
  8. Notice that the command line interface also indicates to you when a tool is being used.

  9. In the Terminal, respond to the next user: prompt with exit to exit the command line interface.

  10. Run the following command to print the poem from the file that the tool created:

    cat crew_poem.txt

    Example output (yours may be a little different):

    United as one, we stand tall, A crew of dreams, ready to enthrall. Through stormy seas or skies so blue, Together we conquer, me and you.
  11. Scroll back in your Terminal history to find where you ran adk run crewai_tool_agent, and notice that the command line interface provided you a log file to tail. Copy and run that command to view more details of the execution:

    tail -F /tmp/agents_log/agent.latest.log
  12. Press CTRL + C to stop tailing the log file and return to the command prompt.

Click Check my progress to verify the objective. Use a CrewAI Tool.

Task 5. Use a Google-provided tool

In this task, you will discover how easy it is to deploy a RAG application using an Agent Development Kit agent with the built-in Vertex AI Search tool from Google and the AI Applications data store you created earlier.

  1. Return to your Cloud Shell Editor tab and select the adk_tools/vertexai_search_tool_agent directory.

  2. Click on the agent.py file in the vertexai_search_tool_agent directory.

  3. Notice the import of the VertexAiSearchTool class:

    from google.adk.tools import VertexAiSearchTool
  4. Update the code where the VertexAiSearchTool is instantiated. In the path being passed to data_store_id, update YOUR_PROJECT_ID to and update YOUR_DATA_STORE_ID to the data store ID you copied earlier.

  5. Add the following line where indicated in the agent definition to provide the agent the tool:

tools=[vertexai_search_tool]
  1. Save the agents.py file.

You can confirm your data store is ready for use by selecting the data store's name on the AI Applications > Data Stores page in the console.

The ACTIVITY and DOCUMENTS tabs provide statuses on the import and indexing of your documents. When the ACTIVITY tab reports "Import completed", your data store should be ready to query.

  1. In the Cloud Shell Terminal, from the adk_tools project directory, launch the command line interface with the following command:

    adk web Note: If you did not shut down your previous adk web session, the default port of 8000 will be blocked, but you can launch the Dev UI with a new port by using adk web --port 8001, for example.
  2. Click the http://127.0.0.1:8000 to open the ADK Dev UI.

  3. From the Select an agent dropdown on the left, select the vertexai_search_tool_agent and toggle on the Token Streaming option in the upper right.

  4. Query the agent about the fictional planet described in your Cloud Storage documents with:

    is the new planet Persephone suitable for habitation?

    Example output (yours may be a little different)

    Based on the "Persephone Survey: What we Know So Far" document, Persephone exhibits several characteristics that suggest it could be habitable: - Location: It orbits within the habitable zone of its star. - Temperature: The average surface temperature is estimated to be around 18°C (64°F). ...
  1. Feel free to ask the agent more questions about this new planet and the conference where its discovery will be announced. When you are satisfied, close the dev UI tab.
  2. When you are finished asking questions of this agent, close the browser tab, select the Cloud Shell Terminal window where the server is running, and press CTRL + C to stop the server.

Click Check my progress to verify the objective. Use a Google-provided tool.

Task 6. Use a function as a custom tool

When pre-built tools don't fully meet specific requirements, you can create your own tools. This allows for tailored functionality, such as connecting to proprietary databases or implementing unique algorithms.

The most straightforward way to create a new tool is to write a standard Python function with a docstring written in a standard format and pass it to your model as a tool. This approach offers flexibility and quick integration.

When writing a function to be used as a tool, there are a few important things to keep in mind:

  • Parameters: Your function can accept any number of parameters, each of which can be of any JSON-serializable type (e.g., string, integer, list, dictionary). It's important to avoid setting default values for parameters, as the large language model (LLM) does not currently support interpreting them.
  • Return type: The preferred return type for a Python Function Tool is a dictionary. This allows you to structure the response with key-value pairs, providing context and clarity to the LLM. For example, instead of returning a numeric error code, return a dictionary with an "error_message" key containing a human-readable explanation. As a best practice, include a "status" key in your return dictionary to indicate the overall outcome (e.g., "success", "error", "pending"), providing the LLM with a clear signal about the operation's state.
  • Docstring: The docstring of your function serves as the tool's description and is sent to the LLM. Therefore, a well-written and comprehensive docstring is crucial for the LLM to understand how to use the tool effectively. Clearly explain the purpose of the function, the meaning of its parameters, and the expected return values.

Define a function and use it as a tool by completing the following steps:

  1. Using the Cloud Shell Editor file explorer, navigate to the directory adk_tools/function_tool_agent.

  2. In the function_tool_agent directory, click on the agent.py file.

  3. Notice that the functions get_date() and write_journal_entry() have docstrings formatted properly for an ADK agent to know when and how to use them. They include:

    • A clear description of what each function does
    • an Args: section describing the function's input parameters with JSON-serializable types
    • a Returns: section describing what the function returns, with the preferred response type of a dict
  4. To pass the function to your agent to use as a tool, add the following code where indicated in the agent.py file:

    tools=[get_date, write_journal_entry]
  5. Save the file.

  6. You will run this agent using the dev UI to see how its tools allow you to easily visualize tool requests and responses. In the Cloud Shell Terminal, from the adk_tools project directory, run the dev UI again with the following command (if the server is still running from before, stop the running server first with CTRL+C, then run the following to start it again):

    adk web
  7. Click the http://127.0.0.1:8000 link in the Terminal output.

  8. A new browser tab will open with the ADK Dev UI.

  9. From the Select an agent dropdown on the left, select the function_tool_agent.

  10. Start a conversation with the agent with:

    hello
  11. The agent should prompt you about your day. Respond with a sentence about how your day is going, and it will write a journal entry for you.

    Example Output:

  12. Notice that your agent shows buttons for your custom tool's request and the response. You can click on each to see more information about each of these events.

  13. Close the dev UI tab.

  14. In the Cloud Shell Editor, you can find your dated journal entry file in the adk_tools directory. (You may want to use the Cloud Shell Editor's menu to enable View > Word Wrap to see the full text without lots of horizontal scrolling.)

  15. To stop the server, click on the Terminal panel and press CTRL + C.

Best practices for writing functions to be used as tools include

  • Fewer Parameters are Better: Minimize the number of parameters to reduce complexity.
  • Use Simple Data Types: Favor primitive data types like str and int over custom classes when possible.
  • Use Meaningful Names: The function's name and parameter names significantly influence how the LLM interprets and utilizes the tool. Choose names that clearly reflect the function's purpose and the meaning of its inputs.
  • Break Down Complex Functions: Instead of a single update_profile(profile: Profile) function, create separate functions like update_name(name: str), update_age(age: int), etc.
  • Return status: Include a "status" key in your return dictionary to indicate the overall outcome (e.g., "success", "error", "pending") to provide the LLM a clear signal about the operation's state.

Click Check my progress to verify the objective. Use a function as a custom tool.

Even More Types of Tools!

The following tool types are good for you to know about, but you will not implement them in this lab.

The LongRunningFunctionTool Class

This tool is a subclass of FunctionTool. It's designed for tasks that require a significant amount of processing time that should be called without blocking the agent's execution.

When using a LongRunningFunctionTool, your Python function can initiate the long-running operation and optionally return an intermediate result to keep the model and user informed about the progress (e.g., status updates or estimated completion time). The agent can then continue with other tasks.

An example is a human-in-the-loop scenario where the agent needs human approval before proceeding with a task.

Agent-as-a-Tool

This feature allows you to leverage the capabilities of other agents within your system by calling them as tools, effectively delegating responsibility to a 'specialist' agent. This is conceptually similar to creating a Python function that calls another agent with function arguments and uses the agent's response as the function's return value.

Application Integration workflows as tools

With Application Integration, you can use a drag-and-drop interface in the Google Cloud Console to build tools, data connections, and data transformations using Integration Connector’s 100+ pre-built connectors for Google Cloud products and third-party systems like Salesforce, ServiceNow, JIRA, SAP, and more. You can then use an ADK ApplicationIntegrationToolset to allow your agents to connect to those sources or call your workflows.

Model Context Protocol (MCP) Tools

Model Context Protocol (MCP) is an open standard designed to standardize how Large Language Models (LLMs) like Gemini and Claude communicate with external applications, data sources, and tools. ADK helps you both use and consume MCP tools in your agents, whether you're trying to build a tool to call an MCP service, or exposing an MCP server for other developers or agents to interact with your tools.

Refer to the MCP Tools documentation for code samples and design patterns that help you use ADK together with MCP servers, including:

  • Using Existing MCP Servers within ADK: An ADK agent can act as an MCP client and use tools provided by external MCP servers.
  • Exposing ADK Tools via an MCP Server: How to build an MCP server that wraps ADK tools, making them accessible to any MCP client.

Congratulations!

In this lab, you’ve learned to:

  • Provide prebuilt Google, LangChain, or CrewAI tools to an agent
  • Discuss the importance of structured docstrings and typing when writing functions for agent tools
  • Write your own tool functions for an agent

Next Steps

To learn more about building and deploying agents using Agent Development Kit, check out these labs:

  • Build multi-agent systems with ADK
  • Deploy ADK agents to Agent Engine

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated May 22, 2025

Lab Last Tested May 22, 2025

Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

This content is not currently available

We will notify you via email when it becomes available

Great!

We will contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.