WatsonxToolkit#

class langchain_ibm.agent_toolkits.utility.toolkit.WatsonxToolkit[source]#

Bases: BaseToolkit

IBM watsonx.ai Toolkit.

Setup

To use, you should have langchain_ibm python package installed, and the environment variable WATSONX_APIKEY set with your API key, or pass it as a named parameter to the constructor.

pip install -U langchain-ibm
export WATSONX_APIKEY="your-api-key"
IBM watsonx.ai for IBM Cloud example:
from langchain_ibm.agent_toolkits.utility import WatsonxToolkit

watsonx_toolkit = WatsonxToolkit(
    url="https://us-south.ml.cloud.ibm.com",
    apikey="*****",
)
tools = watsonx_toolkit.get_tools()

google_search = watsonx_toolkit.get_tool(tool_name="GoogleSearch")

tool_config = {
    "maxResults": 3,
}
google_search.set_tool_config(tool_config)
input = {
    "input": "Search IBM",
}
search_result = google_search.invoke(input)
IBM watsonx.ai software example:
from langchain_ibm.agent_toolkits.utility import WatsonxToolkit

watsonx_toolkit = WatsonxToolkit(
    url="<CPD_URL>",
    username="*****",
    password="*****",
    instance_id="*****",
    version="*****"  # optional
)

rag_query = watsonx_toolkit.get_tool(tool_name="RAGQuery")

rag_query.set_tool_config(
    {
        "vectorIndexId": "<vector-index-id>",
        "projectId": "<project-id>",
    }
)

res = rag_query.run("How to initialize APIClient?")

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

param apikey: SecretStr | None [Optional]#

API key to the watsonx.ai Runtime.

param instance_id: SecretStr | None [Optional]#

Instance_id of the CPD instance.

param password: SecretStr | None [Optional]#

Password to the CPD instance.

param project_id: str | None = None#

ID of the watsonx.ai Studio project.

param space_id: str | None = None#

ID of the watsonx.ai Studio space.

param token: SecretStr | None [Optional]#

Token to the watsonx.ai Runtime.

param url: SecretStr [Optional]#

URL to the watsonx.ai Runtime.

param username: SecretStr | None [Optional]#

Username to the CPD instance.

param verify: str | bool | None = None#

You can pass one of following as verify: * the path to a CA_BUNDLE file * the path of directory with certificates of trusted CAs * True - default path to truststore will be taken * False - no verification will be made

param version: SecretStr | None = None#

Version of the CPD instance.

param watsonx_client: APIClient | None = None#
get_tool(
tool_name: str,
) WatsonxTool[source]#

Get the tool with a given name.

Parameters:

tool_name (str)

Return type:

WatsonxTool

get_tools() list[WatsonxTool][source]#

Get the tools in the toolkit.

Return type:

list[WatsonxTool]