Introduction to AI Voice Agents in Conversational AI in Sales
AI Voice Agents are transforming the way businesses interact with customers. These agents can engage in natural language conversations, providing a seamless interface for customer interaction. In the sales industry, AI Voice Agents are particularly valuable as they can handle customer inquiries, provide product information, and even assist in the purchasing process.
What is an AI Voice Agent
?
An AI
Voice Agent
is a software application that uses artificial intelligence to understand and respond to human speech. It leverages technologies like Speech-to-Text (STT), Language Models (LLM), and Text-to-Speech (TTS) to process and generate human-like responses.Why are they important for the Conversational AI in Sales Industry?
In sales, conversational AI can enhance customer engagement, streamline the sales process, and provide 24/7 support. This leads to increased sales efficiency and customer satisfaction. AI Voice Agents can handle repetitive queries, allowing human agents to focus on more complex tasks.
Core Components of a Voice Agent
- Speech-to-Text (STT): Converts spoken language into text.
- Language Model (LLM): Processes the text to understand and generate responses.
- Text-to-Speech (TTS): Converts the generated text back into speech.
What You'll Build in This Tutorial
In this tutorial, you'll learn how to build a conversational AI
voice agent
for sales using VideoSDK. We'll guide you through setting up the environment, building the agent, and testing it in aplayground environment
.Architecture and Core Concepts
High-Level Architecture Overview
The architecture of an AI
Voice Agent
involves a series of steps from capturing user speech to generating a response. The process begins with capturing audio input, converting it to text, processing it through a language model, and finally converting the response back to speech.
Understanding Key Concepts in the VideoSDK Framework
- Agent: The core class representing your bot, responsible for managing interactions.
Cascading Pipeline
: Manages the flow of audio processing through STT, LLM, and TTS.- VAD &
Turn Detector
: These components help the agent know when to listen and when to speak by detecting voice activity and conversation turns.
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 Python packages:
1pip install videosdk-agents videosdk-plugins
2Step 3: Configure API Keys in a .env file
Create a
.env file in your project directory and add your VideoSDK API key:1VIDEOSDK_API_KEY=your_api_key_here
2Building the AI Voice Agent: A Step-by-Step Guide
Here is the complete code for the AI Voice Agent:
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 Conversational AI Sales Assistant designed to enhance customer engagement and streamline the sales process. Your primary role is to assist potential customers by providing detailed information about products, answering frequently asked questions, and guiding them through the purchasing process. You can also schedule follow-up calls or meetings with sales representatives if needed.\n\nCapabilities:\n1. Provide detailed product information and specifications.\n2. Answer common sales-related questions and objections.\n3. Guide customers through the purchasing process, including payment options and delivery details.\n4. Schedule follow-up calls or meetings with human sales representatives.\n5. Collect customer feedback and preferences to improve sales strategies.\n\nConstraints and Limitations:\n1. You are not authorized to offer discounts or negotiate prices.\n2. You must always include a disclaimer that final purchase decisions should be confirmed with a human sales representative.\n3. You cannot process payments directly; instead, guide customers to the appropriate payment portal.\n4. You must respect customer privacy and comply with data protection regulations.\n5. You should not provide legal or financial advice beyond general product-related 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](https://docs.videosdk.live/ai_agents/core-components/agent-session)(
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 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: YOUR_API_KEY' \\
4 -H 'Content-Type: application/json'
5Step 4.2: Creating the Custom Agent Class
The
MyVoiceAgent class is where we define the behavior of our AI Voice Agent. It inherits from the Agent class and implements two methods: on_enter and on_exit. These methods define what the agent says when a session starts and ends.Step 4.3: Defining the Core Pipeline
The
CascadingPipeline is crucial as it defines how audio is processed. It includes:- DeepgramSTT: Converts speech to text.
- OpenAILLM: Processes the text and generates responses.
- ElevenLabsTTS: Converts text responses back to speech.
- SileroVAD & TurnDetector: Manage voice
activity detection
and turn-taking.
Step 4.4: Managing the Session and Startup Logic
The
start_session function initializes the agent session, sets up the pipeline, and manages the conversation flow. The make_context function creates a job context with room options for the VideoSDK playground.The main block starts the agent job, allowing the agent to run and handle interactions.
Running and Testing the Agent
Step 5.1: Running the Python Script
To start the agent, run the script:
1python main.py
2Step 5.2: Interacting with the Agent in the Playground
Once the agent is running, you'll see a playground link in the console. Use this link to join the session and interact with the AI Voice Agent.
Advanced Features and Customizations
Extending Functionality with Custom Tools
You can extend the agent's capabilities by integrating custom tools. This allows for specialized processing or data handling.
Exploring Other Plugins
The VideoSDK framework supports various plugins for STT, LLM, and TTS. Explore these options to enhance your agent's performance.
Troubleshooting Common Issues
API Key and Authentication Errors
Ensure your API key is correctly set in the
.env file. Double-check for typos or missing keys.Audio Input/Output Problems
Verify your microphone and speaker settings. Ensure permissions are granted for audio access.
Dependency and Version Conflicts
Use a virtual environment to manage dependencies and avoid version conflicts.
Conclusion
Summary of What You've Built
You've successfully built a conversational AI voice agent for sales using VideoSDK. This agent can handle customer interactions, provide product information, and assist in sales processes.
Next Steps and Further Learning
Explore additional plugins and customize your agent further. Consider integrating with CRM systems for enhanced functionality.
Want to level-up your learning? Subscribe now
Subscribe to our newsletter for more tech based insights
FAQ