Build a Real-Time AI Sales Call Assistant

Step-by-step guide to building a real-time AI assistant for sales calls using VideoSDK.

Introduction to AI Voice Agents in AI Assistant Real-Time Sales Call

In today's fast-paced sales environment, leveraging technology to enhance communication and efficiency is crucial. AI Voice Agents are at the forefront of this technological revolution, offering significant advantages in real-time sales calls. But what exactly is an AI

Voice Agent

?

What is an AI

Voice Agent

?

An AI

Voice Agent

is a sophisticated software application designed to interact with users through voice commands. It processes spoken language, understands context, and responds appropriately, mimicking human-like conversation. These agents use a combination of Speech-to-Text (STT), Language Learning Models (LLM), and Text-to-Speech (TTS) technologies to function effectively.

Why are They Important for the AI Assistant Real-Time Sales Call Industry?

In the sales industry, time is money. AI Voice Agents can provide sales representatives with instant access to product information, customer data, and sales scripts during live calls. This real-time assistance can significantly enhance the efficiency and effectiveness of sales interactions, leading to higher conversion rates and improved customer satisfaction.

Core Components of a

Voice Agent

The core components of a

voice agent

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

What You'll Build in This Tutorial

In this tutorial, we'll guide you through building a real-time AI assistant for sales calls using the VideoSDK framework. You'll learn how to set up the environment, create a custom agent, and test it in a live environment.

Architecture and Core Concepts

High-Level Architecture Overview

The architecture of an AI Voice Agent involves several key components working in tandem to process and respond to user inputs. Here’s a high-level overview of the data flow:
Diagram

Understanding Key Concepts in the VideoSDK Framework

Agent

The Agent class is the core representation of your AI voice bot. It handles interactions and manages the flow of conversation.

Cascading Pipeline in AI Voice Agents

The CascadingPipeline orchestrates the flow of audio processing, moving data through stages such as STT, LLM, and TTS.

VAD &

Turn Detector for AI Voice Agents

Voice

Activity Detection

(VAD) and Turn Detection are crucial for determining when the agent should listen and respond, ensuring smooth and natural interactions.

Setting Up the Development Environment

Prerequisites

Before you begin, ensure you have Python 3.11+ installed and a VideoSDK account, which you can create at app.videosdk.live.

Step 1: Create a Virtual Environment

To keep dependencies organized, create a virtual environment:
1python -m venv venv
2source venv/bin/activate  # On Windows use `venv\\Scripts\\activate`
3

Step 2: Install Required Packages

Install the necessary packages using pip:
1pip install videosdk-agents videosdk-plugins
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_api_key_here
2

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

Let’s dive into building the 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 dynamic AI Assistant specialized in real-time sales calls. Your primary role is to assist sales representatives during live calls by providing instant access to product information, customer data, and sales scripts. You can also suggest responses to customer queries and objections based on the context of the conversation. Your capabilities include:\n\n1. Accessing and retrieving relevant product details and specifications.\n2. Analyzing customer data to provide personalized recommendations.\n3. Offering real-time suggestions for handling objections and closing techniques.\n4. Logging call details and outcomes for future reference.\n\nConstraints and Limitations:\n- You are not authorized to make final sales decisions or commitments.\n- You must always defer to the human sales representative for final approval.\n- You cannot access sensitive customer data beyond what is necessary for the call.\n- You must include a disclaimer that all information provided should be verified by the sales representative before acting upon it."
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()
63

Step 4.1: Generating a VideoSDK Meeting ID

To interact with your AI agent, you need a meeting ID. You can generate one using the following curl command:
1curl -X POST "https://api.videosdk.live/v1/rooms" \
2-H "Authorization: Bearer YOUR_API_KEY" \
3-H "Content-Type: application/json" \
4-d '{"name":"Sales Call Room"}'
5

Step 4.2: Creating the Custom Agent Class

The MyVoiceAgent class is where you define the behavior of your AI assistant. It inherits from the Agent class and uses the agent_instructions to guide interactions. The on_enter and on_exit methods define what the agent says at the start and end of a session.

Step 4.3: Defining the Core Pipeline

The

CascadingPipeline

is the heart of your voice agent, connecting various plugins to process audio data:
  • STT (DeepgramSTT): Converts speech to text using the nova-2 model.
  • LLM (OpenAILLM): Uses the gpt-4o model to generate intelligent responses.
  • TTS (ElevenLabsTTS): Converts text back to speech with the eleven_flash_v2_5 model.
  • VAD (SileroVAD): Detects when the user is speaking with a threshold of 0.35.
  • TurnDetector: Manages turn-taking with a threshold of 0.8.

Step 4.4: Managing the Session and Startup Logic

The start_session function initializes the agent and starts the conversation flow. It connects to the VideoSDK session and keeps it running until manually terminated. The make_context function creates a JobContext with room options, enabling the agent to join or create a meeting room.

Running and Testing the Agent

Step 5.1: Running the Python Script

To run your AI voice agent, execute the following command in your terminal:
1python main.py
2

Step 5.2: Interacting with the Agent in the Playground

Once the script is running, you'll receive a playground URL in the console. Open this link in a browser to join the meeting and interact with your AI agent. You can test its capabilities and see how it responds to different sales scenarios.

Advanced Features and Customizations

Extending Functionality with Custom Tools

The VideoSDK framework allows you to extend your agent's functionality with custom tools. This feature enables you to integrate additional capabilities tailored to your specific needs.

Exploring Other Plugins

While this tutorial uses specific plugins, VideoSDK supports various STT, LLM, and TTS options. Explore these alternatives to find the best fit for your application.

Troubleshooting Common Issues

API Key and Authentication Errors

Ensure your API key is correctly set in the .env file. Double-check the VideoSDK dashboard for any updates or changes.

Audio Input/Output Problems

Verify that your microphone and speakers are working correctly. Check the permissions and settings on your device.

Dependency and Version Conflicts

If you encounter issues with dependencies, ensure all packages are up-to-date and compatible with Python 3.11+.

Conclusion

Summary of What You've Built

Congratulations! You've built a real-time AI assistant for sales calls using the VideoSDK framework. This agent can assist sales representatives by providing instant access to critical information during live calls.

Next Steps and Further Learning

Continue exploring the VideoSDK framework to enhance your AI agent's capabilities. Consider integrating more advanced features and experimenting with different plugins to optimize performance.

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