Complexity: 🟢 Beginner
This example demonstrates an end-to-end (E2E) agentic workflow using the NeMo Agent Toolkit library, fully configured through a YAML file. It showcases the NeMo Agent Toolkit plugin system and Builder to seamlessly integrate pre-built and custom tools into workflows.
- Custom Calculator Tools: Demonstrates six tools -
calculator__add,calculator__subtract,calculator__multiply,calculator__divide,calculator__compare, andcurrent_datetimefor mathematical operations and time-based comparisons. - ReAct Agent Integration: Uses a
react_agentthat performs reasoning between tool calls to solve complex mathematical queries requiring multiple steps. - Multi-step Problem Solving: Shows how an agent can break down complex questions like "Is the product of 2 * 4 greater than the current hour?" into sequential tool calls.
- Custom Function Registration: Demonstrates the NeMo Agent Toolkit plugin system for registering custom mathematical functions with proper validation and error handling.
- YAML-based Configuration: Fully configurable workflow that showcases how to orchestrate multiple tools through simple configuration.
If you have not already done so, follow the instructions in the Install Guide to create the development environment and install NeMo Agent Toolkit.
From the root directory of the NeMo Agent Toolkit library, run the following commands:
uv pip install -e examples/getting_started/simple_calculatorIf you have not already done so, follow the Obtaining API Keys instructions to obtain an NVIDIA API key. You need to set your NVIDIA API key as an environment variable to access NVIDIA AI services:
export NVIDIA_API_KEY=<YOUR_API_KEY>
export OPENAI_API_KEY=<YOUR_API_KEY> # OPTIONALReturn to your original terminal, and run the following command from the root of the NeMo Agent Toolkit repo to execute this workflow with the specified input:
nat run --config_file examples/getting_started/simple_calculator/configs/config.yml --input "Is the product of 2 * 4 greater than the current hour of the day?"Expected Workflow Output Note that the output is subject to the time of day when the workflow was run. For this example output, it was run in the afternoon.
No, the product of 2 * 4 (which is 8) is less than the current hour of the day (which is 15).
For a production deployment, use Docker:
Prior to building the Docker image ensure that you have followed the steps in the Installation and Setup section, and you are currently in the NeMo Agent Toolkit virtual environment.
From the root directory of the NeMo Agent Toolkit repository, build the Docker image:
docker build --build-arg NAT_VERSION=$(python -m setuptools_scm) -t simple_calculator -f examples/getting_started/simple_calculator/Dockerfile .Deploy the container:
docker run -p 8000:8000 -p 6006:6006 -e NVIDIA_API_KEY -e OPENAI_API_KEY simple_calculatorNote, a phoenix telemetry service will be exposed at port 6006.
Use the following curl command to test the deployed API:
curl -X 'POST' \
'http://localhost:8000/generate' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"input_message": "Is the product of 2 * 4 greater than the current hour of the day?"}'The API response should be similar to the following:
{
"input": "Is the product of 2 * 4 greater than the current hour of the day?",
"value": "No, the product of 2 * 4 (which is 8) is less than the current hour of the day (which is 16)."
}