Introduction to AI Voice Agents in Live Commerce
AI Voice Agents are revolutionizing the way businesses interact with their customers. These agents can understand and respond to human speech, making them invaluable tools in industries like live commerce. In this tutorial, we will explore how to build an AI
Voice Agent
tailored for live shopping events, enhancing the customer experience by providing real-time product information and support.What is an AI Voice Agent
?
An AI
Voice Agent
is a software application that uses artificial intelligence to process and respond to voice commands. It integrates technologies like Speech-to-Text (STT), Text-to-Speech (TTS), and Language Models (LLM) to understand and generate human-like responses.Why are they important for the live commerce industry?
In live commerce, AI Voice Agents can assist customers by answering queries, suggesting products, and guiding them through the purchasing process. This enhances user engagement and can lead to increased sales.
Core Components of a Voice Agent
- STT (Speech-to-Text): Converts spoken language into text.
- LLM (Large Language Model): Processes the text to generate meaningful responses.
- TTS (Text-to-Speech): Converts text responses back into spoken language.
For a comprehensive understanding of these components, refer to the
AI voice Agent core components overview
.What You'll Build in This Tutorial
In this tutorial, you will learn how to build a fully functional AI
Voice Agent
using the VideoSDK framework. This agent will be capable of interacting with users in a live commerce setting, providing product details, and answering customer questions.Architecture and Core Concepts
High-Level Architecture Overview
The AI Voice Agent processes user speech through a series of components that transform it into a meaningful response. The architecture involves capturing audio input, converting it to text, processing the text with a language model, and then converting the response back to speech.

Understanding Key Concepts in the VideoSDK Framework
- Agent: Represents the core of your AI Voice Agent, handling interactions and managing the conversation flow.
- CascadingPipeline: Manages the flow of audio processing, integrating STT, LLM, and TTS components. Learn more about the
Cascading pipeline in AI voice Agents
. - VAD & TurnDetector: These components help the agent determine when to listen and when to speak, ensuring smooth interactions. Explore the
Turn detector for AI voice Agents
andSilero Voice Activity Detection
for more details.
Setting Up the Development Environment
Prerequisites
To get started, ensure you have Python 3.11+ installed and a VideoSDK account. You can sign up at the VideoSDK website.
Step 1: Create a Virtual Environment
Create a virtual environment to manage your project dependencies:
1python -m venv venv
2source venv/bin/activate # On Windows use `venv\\Scripts\\activate`
3Step 2: Install Required Packages
Install the necessary packages using pip:
1pip install videosdk
2pip install python-dotenv
3Step 3: Configure API Keys in a .env file
Create a
.env file in your project directory to store your VideoSDK API keys securely:1VIDEOSDK_API_KEY=your_api_key_here
2Building the AI Voice Agent: A Step-by-Step Guide
Let's dive into the code to build our AI Voice Agent. Below is the complete, runnable code:
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 knowledgeable and engaging AI Voice Agent specialized in live commerce. Your primary role is to assist users during live shopping events by providing detailed product information, answering customer queries, and facilitating a seamless shopping experience. You can suggest related products, offer promotional details, and guide users through the purchasing process. However, you must always remind users to verify product details and prices on the official website before making a purchase. You are not authorized to process payments or handle sensitive customer information. Always maintain a friendly and professional tone to enhance the shopping experience."
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()
63Step 4.1: Generating a VideoSDK Meeting ID
To interact with the AI Voice Agent, you need a meeting ID. You can generate one using the VideoSDK API:
1curl -X POST \
2 'https://api.videosdk.live/v1/meetings' \
3 -H 'Authorization: Bearer your_api_key_here' \
4 -H 'Content-Type: application/json' \
5 -d '{}'
6Step 4.2: Creating the Custom Agent Class
The
MyVoiceAgent class is where we define the agent's behavior. It inherits from the Agent class and uses the provided instructions to guide interactions.1class MyVoiceAgent(Agent):
2 def __init__(self):
3 super().__init__(instructions=agent_instructions)
4 async def on_enter(self): await self.session.say("Hello! How can I help?")
5 async def on_exit(self): await self.session.say("Goodbye!")
6Step 4.3: Defining the Core Pipeline
The
CascadingPipeline integrates various plugins to handle speech-to-text, language processing, and text-to-speech.1pipeline = CascadingPipeline(
2 stt=DeepgramSTT(model="nova-2", language="en"),
3 llm=OpenAILLM(model="gpt-4o"),
4 tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
5 vad=SileroVAD(threshold=0.35),
6 turn_detector=TurnDetector(threshold=0.8)
7)
8Step 4.4: Managing the Session and Startup Logic
The
start_session function manages the lifecycle of the agent session, ensuring it connects and runs smoothly.1async def start_session(context: JobContext):
2 agent = MyVoiceAgent()
3 conversation_flow = ConversationFlow(agent)
4
5 pipeline = CascadingPipeline(
6 stt=DeepgramSTT(model="nova-2", language="en"),
7 llm=OpenAILLM(model="gpt-4o"),
8 tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
9 vad=SileroVAD(threshold=0.35),
10 turn_detector=TurnDetector(threshold=0.8)
11 )
12
13 session = AgentSession(
14 agent=agent,
15 pipeline=pipeline,
16 conversation_flow=conversation_flow
17 )
18
19 try:
20 await context.connect()
21 await session.start()
22 await asyncio.Event().wait()
23 finally:
24 await session.close()
25 await context.shutdown()
26Running and Testing the Agent
Step 5.1: Running the Python Script
To run your AI Voice Agent, execute the following command:
1python main.py
2Step 5.2: Interacting with the Agent in the Playground
Once the script is running, you will see a link to the VideoSDK playground in the console. Use this link to join the session and interact with your agent.
Advanced Features and Customizations
Extending Functionality with Custom Tools
You can further enhance your AI Voice Agent by integrating custom tools and plugins to handle specific tasks or improve performance.
Exploring Other Plugins
VideoSDK supports various plugins for STT, LLM, and TTS. Explore these options to find the best fit for your needs.
Troubleshooting Common Issues
API Key and Authentication Errors
Ensure your API keys are correctly configured in the
.env file and that you have the necessary permissions.Audio Input/Output Problems
Check your microphone and speaker settings to ensure they are working correctly.
Dependency and Version Conflicts
Use a virtual environment to manage dependencies and avoid conflicts between package versions.
Conclusion
Summary of What You've Built
In this tutorial, you have built a powerful AI Voice Agent for live commerce using the VideoSDK framework. This agent can interact with users, providing product information and support during live shopping events.
Next Steps and Further Learning
Explore additional features and plugins to further enhance your agent's capabilities. Consider integrating with other APIs to expand its functionality. For more detailed session management, refer to
AI voice Agent Sessions
.Want to level-up your learning? Subscribe now
Subscribe to our newsletter for more tech based insights
FAQ