Authoring Python-Based Tools

Python tools are one of the most flexible and powerful ways to extend agent functionality in watsonx Orchestrate, especially when combined with Flows. A Python tool consists of one or more Python files. Within these files, you define one or more functions and annotate them with the @tool decorator to expose them to Orchestrate. Each Python tool runs inside an isolated container with its own virtual environment. This ensures that the tool and its dependencies remain sandboxed from the host operating system, providing a secure and consistent runtime. Python tool example
Python
#test_tool.py
from ibm_watsonx_orchestrate.agent_builder.tools import tool


@tool()
def my_tool(input: str) -> str:
    """Executes the tool's action based on the provided input.

    Args:
        input (str): The input of the tool.

    Returns:
        str: The action of the tool.
    """

    #functionality of the tool

    return f"Hello, {input}"
Note:
Python tools must use Google-style docstrings to apply descriptions and document the tool.

Importing Python-Based Tools

To import a Python tool use the orchestrate tools import command using the -f flag to specify which python file contains your tool definitions. Each @tool annotated in the given file will be exposed as a tool within your active watsonx Orchestrate environment. It is recommended to include only a single @tool annotated function per file so that tools can be imported independently.
BASH
orchestrate tools import -k python -f my-tool.py -r requirements.txt -a app1 -a app2

Additional features of Python tools

Common pitfalls of Python tools

Host networking

  • On watsonx Orchestrate Developer Edition: Because Python tools run within a container, localhost within a Python tool refers to the container executing the tool, not the host machine. To call an endpoint on your host machine, use a URL of docker.host.internal or explicitly use your host machine’s IP address.
  • On SaaS: The SaaS version of watsonx Orchestrate does not have access to the internal network of your company. If this access is necessary it is possible to prototype with the Developer Edition and then deploy watsonx Orchestrate via the Cloud Pak for Data, on-premises, or by engaging with IBM for alternatives.
  • On CPD (On-premises): for a tool to be able to access the external internet resources, ensure that no firewall rules prevent access to that resource from the node pool responsible for tool execution.

Read only filesystem

For the safety and security of the watsonx Orchestrate runtime, the filesystem your tool executes in, your tool has read only access to its own filesystem. This means it is not possible to update files during tool execution.