Skip to main content
WatsonxToolkit is a wrapper for IBM watsonx.ai Toolkit.
This example shows how to use watsonx.ai Toolkit using LangChain.

Overview

Integration details

Setup

To access IBM watsonx.ai toolkit you’ll need to create an IBM watsonx.ai account, get an API key, and install the langchain-ibm integration package.

Credentials

This cell defines the WML credentials required to work with watsonx Toolkit. Action: Provide the IBM Cloud user API key. For details, see documentation.
Additionaly you are able to pass additional secrets as an environment variable.

Installation

The LangChain IBM integration lives in the langchain-ibm package:

Instantiation

Initialize the WatsonxToolkit class.
Alternatively, you can use Cloud Pak for Data credentials. For details, see watsonx.ai software setup. For certain requirements, there is an option to pass the IBM’s APIClient object into the WatsonxToolkit class.

Tools

Get all tools

It is possible to get all available tools as a list of WatsonxTool objects.
The list of available tools may vary depending on whether it is IBM watsonx.ai for IBM Cloud or IBM watsonx.ai software.

Get a tool

You can also get a specific WatsonxTool by name.

Invocation

Invoke the tool with a simple input

To fetch a list of received results, you can execute the below cell.

Invoke the tool with a configuration

To check if a tool has a config schema and view its properties you can look at the tool’s tool_config_schema. In this example, the tool has a config schema that contains maxResults parameter to set maximum number of results to be returned.
To set tool_config parameters, you need to use set_tool_config() method and pass correct dict according to above tool_config_schema.
There is supposed to be maximum 3 results.

Invoke the tool with an input schema

We need to get another tool (with an input schema) for the example purpose.
To check if a tool has an input schema and view its properties, you can look at the tool’s tool_input_schema. In this example, the tool has an input schema that contains one required and one optional parameter.
To correctly pass an input to invoke(), you need to create an invoke_input dictionary with required parameter as a key with its value.
This time the output is a single string value. To fetch and print it you can execute the below cell.

Invoke the tool with a ToolCall

We can also invoke the tool with a ToolCall, in which case a ToolMessage will be returned:

Use within an agent

API reference

For detailed documentation of all WatsonxToolkit features and configurations head to the API reference.