Build AI Voice Agent for Hospitality

Step-by-step guide to building an AI Voice Agent for the hospitality industry using VideoSDK.

Introduction to AI Voice Agents in the Hospitality Industry

AI Voice Agents are revolutionizing the way businesses interact with customers, and the hospitality industry is no exception. These agents can handle a variety of tasks, from answering frequently asked questions to assisting with bookings and providing information about local attractions.

What is an AI Voice Agent?

An AI Voice Agent is a software application that uses artificial intelligence to interpret and respond to human speech. It combines technologies like speech-to-text (STT), language processing (LLM), and text-to-speech (TTS) to engage in natural conversations.

Why are they important for the hospitality industry?

In the hospitality sector, AI Voice Agents can enhance guest experiences by providing 24/7 service, reducing wait times, and offering personalized recommendations. They can assist with room service orders, provide information about hotel amenities, and even suggest local dining options.

Core Components of a Voice Agent

  • STT (Speech-to-Text): Converts spoken language into text.
  • LLM (Large Language Model): Processes the text to understand and generate responses.
  • TTS (Text-to-Speech): Converts the generated text back into spoken language.

What You'll Build in This Tutorial

In this guide, you will learn to build an AI Voice Agent tailored for the hospitality industry using the VideoSDK framework. By the end, you'll have a fully functional agent capable of interacting with guests and providing useful information. For a detailed walkthrough, refer to the

Voice Agent Quick Start Guide

.

Architecture and Core Concepts

Understanding the architecture of an AI Voice Agent is crucial to building one effectively. Let's explore the high-level architecture and key concepts involved.

High-Level Architecture Overview

The AI Voice Agent operates by converting user speech into text, processing the text to generate a response, and then converting the response back into speech. Here's a simplified flow:
1sequenceDiagram
2    participant User
3    participant Agent
4    participant STT
5    participant LLM
6    participant TTS
7    User->>Agent: Speaks
8    Agent->>STT: Convert speech to text
9    STT->>Agent: Text
10    Agent->>LLM: Process text
11    LLM->>Agent: Response
12    Agent->>TTS: Convert response to speech
13    TTS->>User: Speaks
14

Understanding Key Concepts in the VideoSDK Framework

  • Agent: The core class representing your bot, responsible for handling interactions.
  • CascadingPipeline: Manages the flow of audio processing through various stages like STT, LLM, and TTS. Learn more about the

    Cascading pipeline in AI voice Agents

    .
  • VAD & TurnDetector: These components help the agent know when to listen and when to speak, ensuring smooth interactions. For more details, see the

    Turn detector for AI voice Agents

    .

Setting Up the Development Environment

Before diving into code, let's set up the development environment.

Prerequisites

Ensure you have Python 3.11+ installed and a VideoSDK account. You can sign up at app.videosdk.live.

Step 1: Create a Virtual Environment

Create a virtual environment to manage dependencies:
1python -m venv venv
2source venv/bin/activate  # On Windows use `venv\\Scripts\\activate`
3

Step 2: Install Required Packages

Install the necessary Python packages:
1pip install videosdk agents silero deepgram openai elevenlabs
2

Step 3: Configure API Keys in a .env file

Create a .env file in your project directory and add your API keys:
1VIDEOSDK_API_KEY=your_videosdk_api_key
2DEEPGRAM_API_KEY=your_deepgram_api_key
3OPENAI_API_KEY=your_openai_api_key
4ELEVENLABS_API_KEY=your_elevenlabs_api_key
5

Building the AI Voice Agent: A Step-by-Step Guide

Now, let's build the AI Voice Agent. Below is the complete, runnable code. We will break it down into smaller parts for detailed explanations.
1import asyncio, os
2from videosdk.agents import Agent, AgentSession, CascadingPipeline, JobContext, RoomOptions, WorkerJob, ConversationFlow
3from videosdk.plugins.silero import SileroVAD
4from videosdk.plugins.turn_detector import TurnDetector, pre_download_model
5from videosdk.plugins.deepgram import DeepgramSTT
6from videosdk.plugins.openai import OpenAILLM
7from videosdk.plugins.elevenlabs import ElevenLabsTTS
8from typing import AsyncIterator
9
10# Pre-downloading the Turn Detector model
11pre_download_model()
12
13agent_instructions = "You are a friendly and knowledgeable AI Voice Agent designed specifically for the hospitality industry. Your primary role is to assist guests by providing information about hotel services, local attractions, dining options, and booking amenities. You can answer frequently asked questions, provide recommendations based on guest preferences, and help with room service orders. However, you must always remind users that you are an AI and not a human concierge, and for complex requests or emergencies, guests should contact the hotel staff directly. You should also ensure that all personal data is handled in compliance with privacy regulations and never store sensitive information."
14
15class MyVoiceAgent(Agent):
16    def __init__(self):
17        super().__init__(instructions=agent_instructions)
18    async def on_enter(self): await self.session.say("Hello! How can I help?")
19    async def on_exit(self): await self.session.say("Goodbye!")
20
21async def start_session(context: JobContext):
22    # Create agent and conversation flow
23    agent = MyVoiceAgent()
24    conversation_flow = ConversationFlow(agent)
25
26    # Create pipeline
27    pipeline = CascadingPipeline(
28        stt=DeepgramSTT(model="nova-2", language="en"),
29        llm=OpenAILLM(model="gpt-4o"),
30        tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
31        vad=SileroVAD(threshold=0.35),
32        turn_detector=TurnDetector(threshold=0.8)
33    )
34
35    session = AgentSession(
36        agent=agent,
37        pipeline=pipeline,
38        conversation_flow=conversation_flow
39    )
40
41    try:
42        await context.connect()
43        await session.start()
44        # Keep the session running until manually terminated
45        await asyncio.Event().wait()
46    finally:
47        # Clean up resources when done
48        await session.close()
49        await context.shutdown()
50
51def make_context() -> JobContext:
52    room_options = RoomOptions(
53    #  room_id="YOUR_MEETING_ID",  # Set to join a pre-created room; omit to auto-create
54        name="VideoSDK Cascaded Agent",
55        playground=True
56    )
57
58    return JobContext(room_options=room_options)
59
60if __name__ == "__main__":
61    job = WorkerJob(entrypoint=start_session, jobctx=make_context)
62    job.start()
63

Step 4.1: Generating a VideoSDK Meeting ID

To start, you need a meeting ID. You can generate one using the VideoSDK API. Here's a curl command example:
1curl -X POST https://api.videosdk.live/v1/rooms \
2-H "Authorization: Bearer YOUR_VIDEOSDK_API_KEY" \
3-H "Content-Type: application/json" \
4-d '{"name": "My Meeting Room"}'
5

Step 4.2: Creating the Custom Agent Class

The MyVoiceAgent class is where you define the behavior of your agent. It inherits from the Agent class and specifies what happens when the agent enters or exits a session.

Step 4.3: Defining the Core Pipeline

The CascadingPipeline is crucial as it defines the flow of data through the agent. Each plugin in the pipeline has a specific role:

Step 4.4: Managing the Session and Startup Logic

The start_session function handles the setup and execution of the agent's session. It creates the agent, sets up the conversation flow, and manages the pipeline. The make_context function prepares the job context, including room options for the session. For more interactive testing, consider using the

AI Agent playground

.

Running and Testing the Agent

With the code in place, it's time to run and test your AI Voice Agent.

Step 5.1: Running the Python Script

Execute the script using Python:
1python main.py
2

Step 5.2: Interacting with the Agent in the Playground

After running the script, check the console for a playground URL. Open this URL in your browser to interact with your agent. Speak into your microphone, and the agent will respond based on its programming.

Advanced Features and Customizations

Once you have the basics down, consider extending your agent's functionality.

Extending Functionality with Custom Tools

You can add custom tools to your agent to handle specific tasks or integrate additional services.

Exploring Other Plugins

The VideoSDK framework supports various plugins. Experiment with different STT, LLM, and TTS options to find the best fit for your needs.

Troubleshooting Common Issues

Even with a well-documented guide, you might encounter issues. Here are some common problems and their solutions.

API Key and Authentication Errors

Ensure your API keys are correctly set in the .env file and that your account has the necessary permissions.

Audio Input/Output Problems

Check your microphone and speaker settings. Ensure the correct devices are selected in your system settings.

Dependency and Version Conflicts

Use a virtual environment to manage dependencies. Check for version conflicts if you encounter errors during package installation.

Conclusion

Congratulations! You've built a fully functional AI Voice Agent for the hospitality industry. This agent can assist guests with various inquiries, enhancing their experience. For more insights into managing sessions, refer to

AI voice Agent Sessions

.

Next Steps and Further Learning

Explore more advanced features of the VideoSDK framework, and consider integrating additional services to expand your agent's capabilities.

Start Building With Free $20 Balance

No credit card required to start.

Want to level-up your learning? Subscribe now

Subscribe to our newsletter for more tech based insights

FAQ