In addition to the tools provided by watsonx.ai within the Agent Lab, you can also choose to create your own tool that takes in custom inputs and generates a specific output. Your agent can choose to use the custom tool in conjunction with other tools in the agent's configuration to generate a response to a user's question.
Configuring a custom tool
To create a custom tool in the Agent Lab, you must define several details that the agent framework uses to register and run the tool as follows:
-
To set up your custom tool, specify a name and describe the main functions the tool performs.
Important: Provide a detailed description of what the custom tool does including accepted inputs and the format of the tool's response. The information is consumed as input context by the foundation model to decide whether the agent framework should use the tool to generate the agent's final response. -
Define the format of the inputs your custom tool accepts as a JSON schema. Specify a variable name for each input, what the input represents, and the input's data type.
-
Define a Python function that accepts the input variables defined in the JSON schema as arguments and returns a specific response. Currently, you can only define one Python function that runs the core logic for your custom tool.
Note:You cannot install Python code packages, but you can import packages that are included with watsonx.ai. From the home page of your project, click the Manage tab. Click Environments, and then click the Templates tab. Open the Runtime 24.1 on Python 3.11 S template to see a list of included packages. -
Optional: You can test and debug your function by providing example inputs and running your custom tool to validate that the function is generating the correct result.
Restriction: You can test one set of inputs at a time. To use a different set of values as test inputs, you must manually edit the test input JSON schema and re-run your code. -
Click Create to add your custom tool to the agent.
-
Optional: You can click the Configure icon to update the custom tool configuration.
Example of a custom tool created in Agent Lab
When you choose to create a custom tool, you can develop the tool incrementally on the Define page. You must specify the type of inputs the tool accepts and define a Python function that runs when the agent framework calls the custom tool. On the Test page, you can provide sample test inputs and run your function to validate your code.
The following example defines a custom tool that calculates the product of two integers. You specify each input paramater and define a Python function that accepts each input and performs the multiplication operation.
-
Name your custom tool and provide a detailed description for the tool, including the input and output formats, and the main task the tool performs. For example:
Name: Multiple numbers
Description: Use this tool when multiplying two numbers. The tool consists of a Python function named "multiply". The function takes two parameters, "number_1" and "number_2". Both parameters are expected to be numerical values, which can only be integers numbers. The tool's primary operation is to multiply two input numbers by using the '*' operator in Python, which performs multiplication. The result of the operation is returned as the output of the tool.
-
Provide a JSON schema that defines the input parameters for your Python function, including a name, data type and description for each parameter:
{ "number_1": { "title": "Number 1", "description": "The first number to multiply", "type": "integer" }, "number_2": { "title": "Number 2", "description": "The second number to multiply", "type": "integer" } }
-
Define a Python function that accepts two numbers as inputs, multiplies the values, and returns the result.
def multiply (number_1, number_2): return number_1 * number_2
-
On the Test page, a JSON schema for the test inputs is autogenerated based on the JSON schema you define for the arguments to your Python function. Provide two integers as input to your function as follows:
{ "number_1": 4, "number_2": 5 }
-
Click the Run to test your code and validate the result. The Results pane will display 20 as the product.
Parent topic: Agent Lab