Skip to main content
This tutorial walks you through implementing client-side tools in Ultravox to create real-time, interactive UI elements. You’ll build a drive-thru order display screen that updates dynamically as customers place orders through an AI agent. What you’ll learn:
  • How to define and implement client tools
  • Real-time UI updates using custom events
  • State management with React components
  • Integration with Ultravox’s AI agent system
Time to complete: 30 minutes

Prerequisites

Before starting this tutorial, make sure you have:
  • Basic knowledge of TypeScript and React
  • The starter code from our tutorial repository
  • Node.js 16+ installed on your machine

Understanding Client Tools

Client tools in Ultravox enable direct interaction between AI agents and your frontend application. Unlike server-side tools that handle backend operations, client tools are specifically designed for:
  • UI Updates → Modify interface elements in real-time
  • State Management → Handle application state changes
  • User Interaction → Respond to and process user actions
  • Event Handling → Dispatch and manage custom events

Project Overview: Dr Donut Drive-Thru

We’ll build a drive-thru order display for a fictional restaurant called “Dr. Donut”. The display will update in real-time as customers place orders through our AI agent. This tutorial will take you through the following steps:

Implementation Steps

1

Define the Tool

Create a schema for order updates
2

Implement Logic

Build the tool’s functionality
3

Register the Tool

Connect it to the Ultravox system
4

Create the UI

Build the order display component
Stuck?
If at any point you get lost, you can refer to the /final folder in the repo to get final versions of the various files you will create or edit.

Step 1: Define the Tool

First, we’ll define our updateOrder tool that the AI agent will use to modify the order display. Modify .demo-config.ts:
Here’s what this is doing:
  • Defines a client tool called updateOrder and describes what it does and how to use it.
  • Defines a single, required parameter called orderDetailsData that:
    • Is passed in the request body
    • Is an array of objects where each object can contain name, quantity, specialInstructions, and price. Only specialInstructions is optional.

Update System Prompt

Now, we need to update the system prompt to tell the agent how to use the tool. Update the sysPrompt variable:

Update Configuration + Import

Now we need to add the selectedTools to our call definition and update our import statement. Add the tool to your demo configuration:
Add ParameterLocation and SelectedTool to our import:

Step 2: Implement Tool Logic

Now that we’ve defined the updateOrder tool, we need to implement the logic for it. Create /lib/clientTools.ts to handle the tool’s functionality:
We will do most of the heavy lifting in the UI component that we’ll build in step 4.

Step 3: Register the Tool

Next, we are going to register the client tool with the Ultravox client SDK. Update /lib/callFunctions.ts:

Step 4: Build the UI

Create a new React component to display order details. This component will:
  • Listen for order updates
  • Format currency and order items
  • Handle order clearing when calls end
Create /components/OrderDetails.tsx:

Add to Main Page

Update the main page (page.tsx) to include the new component:

Testing Your Implementation

  1. Start the development server:
  2. Navigate to http://localhost:3000
  3. Start a call and place an order. You should see:
    • Real-time updates to the order display
    • Formatted prices and item details
    • Special instructions when provided
    • Order clearing when calls end

Next Steps

Now that you’ve implemented basic client tools, you can:
  • Add additional UI features like order modification or nutritional information
  • Add animations for updates
  • Enhance the display with customer and/or vehicle information

Resources