Create tools for your agents. With ADK, tools can be created using a Python program or an OpenAPI specification.

Creating Python-Based Tools

Python tools are created based on the functions of a Python file. To create a Python-based tool, include the @tool decorator and a docstring in your python function. These elements identify the function to be converted into a tool and provide a description that helps the agent understand the tool’s usage.

Apart from the mandatory @tool decorator and docstring, you can design your Python function as needed to perform the desired actions. If your function requires inputs and outputs, you can use native Python types and Pydantic typings.

Python tool example

[Python]
#test_tool.py
from ibm_watsonx_orchestrate.agent_builder.tools import tool, ToolPermission


@tool(name="myName", description="the description", permission=ToolPermission.ADMIN)
def my_tool(input: str) -> str:

   """
   This is my tool.

   :param input: The input of my tool.
   :returns: The action of my tool.
   """

   #functionality of the tool

If your Python function relies on external libraries or packages, you can ensure your tool works correctly by specifying these dependencies in the requirements.txt file.

Python tool example

[Python]
#test_tool.py
import pytz
from timezonefinder import TimezoneFinder
from ibm_watsonx_orchestrate.agent_builder.tools import tool, ToolPermission


@tool(name="myName", description="the description", permission=ToolPermission.ADMIN)
def my_tool(input: str) -> str:

   """
   This is my tool.

   :param input: The input of my tool.
   :returns: The action of my tool.
   """

   #functionality of the tool

requirements.txt example

[TXT]
pytz
timezonefinder

Creating OpenAPI based tools

OpenAPI tools are created based on an OpenAPI specification file. To import an OpenAPI tool, configure the servers and paths properties; the entire OpenAPI specification file is not required.

OpenAPI tool example

[YAML]
servers:
- url: mytoolserver
paths:
/:
   get:
      operationId: myTool
      summary: myName
      description: the description
      requestBody:
         ...
      responses:
         ...