By Markus van Kempen |
Series: WXO Labs & Tutorial Guide (Part 1 of 15)
Interactive Lab Portal: https://markusvankempen.github.io/wxo-labs/
GitHub Repository: https://github.com/markusvankempen/wxo-labs
Large Language Models (LLMs) are great at conversational synthesis, but on their own, they cannot query your company database, call an internal microservice, or run deterministic business calculations.
In IBM watsonx Orchestrate (WXO), tools give your AI agents hands and feet. You can write custom logic in plain Python, decorate it with @tool, and publish it directly to your Orchestrate catalog. From there, the LLM autonomously extracts parameters from conversational dialogue and executes your Python code.
In this quick, hands-on tutorial (adapted from Lab 1 of our WXO Labs & Tutorial Guide), we will build, deploy, and chat with your very first custom Python tool and native AI agent from scratch in under 15 minutes.
Before starting, ensure you have:
pip install ibm-watsonx-orchestrate
Verify your CLI environment is active:
orchestrate env list
Create a new folder for your project and create a file named greetings.py:
from ibm_watsonx_orchestrate import tool
@tool
def greet_user(name: str) -> str:
"""
Generate a personalized greeting for a user.
Args:
name: The name of the person to greet.
Returns:
A friendly greeting message.
"""
return f"Hello, {name}! Welcome to IBM watsonx Orchestrate."
What makes this work?
Args: documentation to decide when to call the tool and which arguments to parse from the user prompt!Create a requirements.txt file in the same directory to declare the tool dependency:
ibm-watsonx-orchestrate>=2.9.0
Run the following CLI command to package and upload your Python tool to your Orchestrate environment:
orchestrate tools import -k python -f greetings.py -r requirements.txt
You should see:
[INFO] - Successfully imported tool 'greet_user'
Verify that it appears in your catalog:
orchestrate tools list | grep greet_user
Now let's build an AI agent that knows how to use our new tool. Create a file named agent.yaml:
spec_version: v1
kind: native
name: hello_world_greeter
title: "Hello World Greeter"
description: "A friendly onboarding agent that greets users using custom Python tools."
model: ibm/granite-3-8b-instruct
instructions: |
You are a friendly and welcoming assistant.
When a user introduces themselves or asks you to greet someone, extract their name
and call the `greet_user` tool to deliver a personalized welcome.
tools:
- greet_user
Import and deploy your agent with two simple commands:
# 1. Import the agent manifest
orchestrate agents import -f agent.yaml
# 2. Deploy to active environment
orchestrate agents deploy -n hello_world_greeter
Now, test your agent conversationally in your terminal:
orchestrate chat ask -n hello_world_greeter "Say hello to Markus"
Live Response:
[hello_world_greeter] Hello, Markus! Welcome to IBM watsonx Orchestrate.
The agent parsed your prompt, recognized that it should greet "Markus", extracted name="Markus", called greet_user(name="Markus") in Python, and returned the greeting!
Try modifying greetings.py to support a language parameter:
from ibm_watsonx_orchestrate import tool
@tool
def greet_user(name: str, language: str = "en") -> str:
"""
Generate a personalized greeting in the requested language.
Args:
name: The person to greet.
language: Language code ('en' for English, 'es' for Spanish, 'fr' for French, 'de' for German).
"""
greetings = {
"en": f"Hello, {name}! Welcome to IBM watsonx Orchestrate.",
"es": f"¡Hola, {name}! Bienvenido a IBM watsonx Orchestrate.",
"fr": f"Bonjour, {name}! Bienvenue dans IBM watsonx Orchestrate.",
"de": f"Guten Tag, {name}! Willkommen bei IBM watsonx Orchestrate."
}
return greetings.get(language.lower(), greetings["en"])
Re-import the tool:
orchestrate tools import -k python -f greetings.py -r requirements.txt
Now ask your agent:
orchestrate chat ask -n hello_world_greeter "Greet Carlos in Spanish"
The agent will automatically map language="es" and reply in Spanish!
Congratulations! You have completed Lab 1. This is the first of 15 progressive hands-on labs designed to take you from foundational Python tools to enterprise production architectures:
Explore the complete interactive curriculum and source code:
Author: Markus van Kempen | mvk@ca.ibm.com
Research | Floor 7½ 🏢🤏
No bug too small, no syntax too weird.