Skip to main content
Learn how to implement customer service escalation in Ultravox using call stages to handle customer complaints by transferring them to a manager. What you’ll learn:
  • How to implement an escalation tool
  • How to use call stages to switch conversation context
  • How to handle manager takeover with a new system prompt
  • Testing escalation scenarios
Time to complete: 25 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
  • ngrok installed on your machine

Understanding Call Stages

Call stages in Ultravox enable dynamic changes to an ongoing conversation by:
  • Switching system prompts mid-conversation
  • Changing voice personalities
  • Maintaining conversation context
  • Handling role transitions seamlessly
In this tutorial, we’ll use call stages to transfer angry customers to a manager who can better handle their complaints.

Project Overview: Dr. Donut Manager Escalation

We’ll build an escalation system for our Dr. Donut drive-thru that allows the AI agent to transfer difficult situations to a manager. The system will:
  1. Recognize when a customer needs manager assistance
  2. Collect complaint details
  3. Switch to a manager persona with authority to resolve issues

Implementation Steps

1

Set Up ngrok

Enable external access to our escalation endpoint
2

Define the Tool

Create a schema for escalation requests
3

Create Manager Handler

Build the API route for manager takeover
4

Update System Prompt

Add escalation rules to the base prompt
5

Test the System

Verify escalation flows
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.
Debugging
During testing, watch your terminal for ngrok request logs to verify the escalation endpoint is being called correctly.

Step 1: Set Up ngrok

First, we need to make our escalation endpoint accessible to Ultravox.
  1. Start your development server:
  1. In a new terminal, start ngrok:
  1. Copy the HTTPS URL from ngrok (it will look like https://1234-56-78-910-11.ngrok-free.app)
  2. Update toolsBaseUrl in demo-config.ts:

Step 2: Define the Escalation Tool

We’ll define an escalateToManager tool that the AI agent will use to transfer difficult customers. Update the selectedTools array in demo-config.ts and add to our call definition:

Step 3: Create Manager Handler

Create a new file at app/api/managerEscalation/route.ts to handle the escalation:

Step 4: Update System Prompt

Add escalation rules to your base system prompt in demo-config.ts:

Testing Your Implementation

Here are three scenarios to test the escalation system:

Scenario 1: Food Quality Issue

Scenario 2: Out of Stock Frustration

Scenario 3: Product and Refund

For each scenario, verify:
  1. The agent offers manager assistance
  2. The escalation tool is called with appropriate details
  3. The manager persona takes over with the new voice
  4. The manager follows the resolution guidelines

Common Issues

  1. ngrok URL Not Working
    • Make sure ngrok is running
    • Check the URL is correctly copied to demo-config.ts
    • Verify no trailing slash in the URL
  2. Escalation Not Triggering
    • Check the system prompt includes escalation guidelines
    • Verify the complaint is clearly expressed
    • Try using keywords like “manager”, “refund”, or “complaint”
  3. Manager Voice Not Changing
    • Verify the X-Ultravox-Response-Type header is set
    • Check the voice parameter in the response body

Next Steps

Now that you’ve implemented basic escalation, you can:
  • Implement different manager personalities for different situations
  • Create a complaint logging system
  • Add resolution tracking and follow-up mechanisms

Resources