CRM Integration with AI Voice Agents

Build AI Voice Agents for CRM integration with this comprehensive guide. Includes code examples and testing instructions.

Introduction to AI Voice Agents in CRM Integration

AI Voice Agents are transforming the way businesses interact with customers by providing seamless, real-time communication. These agents use advanced technologies like Speech-to-Text (STT), Text-to-Speech (TTS), and Large Language Models (LLM) to understand and respond to human speech.

What is an AI Voice Agent?

An AI Voice Agent is a software application that can interpret human speech, process the information, and respond in a natural language. It acts as an interface between humans and machines, enabling efficient communication.

Why are they important for CRM integration?

In the CRM industry, AI Voice Agents can automate routine tasks, provide instant customer support, and enhance data management. They help in retrieving and updating customer information, scheduling follow-ups, and summarizing interactions, making them invaluable for businesses looking to improve customer relationships.

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 text responses back into speech.
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 guide, you will learn to build a CRM-integrated AI Voice Agent using the VideoSDK framework. We will cover everything from setting up your environment to running and testing your agent. To get started quickly, refer to the

Voice Agent Quick Start Guide

.

Architecture and Core Concepts

Understanding the architecture of an AI Voice Agent is crucial for successful implementation.

High-Level Architecture Overview

The data flow in an AI Voice Agent starts with user speech, which is converted to text using STT. The text is then processed by an LLM to generate a response, which is converted back to speech using TTS. This entire process is managed by a pipeline that ensures smooth operation.
1sequenceDiagram
2    participant User
3    participant Agent
4    participant STT
5    participant LLM
6    participant TTS
7    User->>Agent: Speak
8    Agent->>STT: Convert Speech to Text
9    STT-->>Agent: Text
10    Agent->>LLM: Process Text
11    LLM-->>Agent: Response
12    Agent->>TTS: Convert Text to Speech
13    TTS-->>User: Speak Response
14

Understanding Key Concepts in the VideoSDK Framework

Setting Up the Development Environment

Before building your AI Voice Agent, you need to set up your development environment.

Prerequisites

  • Python 3.11+: Ensure you have Python 3.11 or higher installed.
  • VideoSDK Account: Sign up at app.videosdk.live to access necessary APIs.

Step 1: 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 VideoSDK and other dependencies using pip.
1pip install videosdk-agents videosdk-plugins-silero videosdk-plugins-turn-detector videosdk-plugins-deepgram videosdk-plugins-openai videosdk-plugins-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_api_key_here
2DEEPGRAM_API_KEY=your_deepgram_api_key_here
3ELEVENLABS_API_KEY=your_elevenlabs_api_key_here
4OPENAI_API_KEY=your_openai_api_key_here
5

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

Here is the complete code for the AI Voice Agent that integrates with CRM systems.
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 = "{
14  \"persona\": \"efficient CRM assistant\",
15  \"capabilities\": [
16    \"integrate seamlessly with CRM systems\",
17    \"retrieve and update customer information\",
18    \"schedule follow-up calls and meetings\",
19    \"provide summaries of customer interactions\",
20    \"assist with CRM data entry and management\"
21  ],
22  \"constraints\": [
23    \"you are not authorized to make financial transactions\",
24    \"ensure data privacy and comply with GDPR\",
25    \"do not provide personal opinions or advice\",
26    \"always verify customer identity before sharing sensitive information\"
27  ]
28}"
29
30class MyVoiceAgent(Agent):
31    def __init__(self):
32        super().__init__(instructions=agent_instructions)
33    async def on_enter(self): await self.session.say("Hello! How can I help?")
34    async def on_exit(self): await self.session.say("Goodbye!")
35
36async def start_session(context: JobContext):
37    # Create agent and conversation flow
38    agent = MyVoiceAgent()
39    conversation_flow = ConversationFlow(agent)
40
41    # Create pipeline
42    pipeline = CascadingPipeline(
43        stt=DeepgramSTT(model="nova-2", language="en"),
44        llm=OpenAILLM(model="gpt-4o"),
45        tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
46        vad=SileroVAD(threshold=0.35),
47        turn_detector=TurnDetector(threshold=0.8)
48    )
49
50    session = AgentSession(
51        agent=agent,
52        pipeline=pipeline,
53        conversation_flow=conversation_flow
54    )
55
56    try:
57        await context.connect()
58        await session.start()
59        # Keep the session running until manually terminated
60        await asyncio.Event().wait()
61    finally:
62        # Clean up resources when done
63        await session.close()
64        await context.shutdown()
65
66def make_context() -> JobContext:
67    room_options = RoomOptions(
68    #  room_id="YOUR_MEETING_ID",  # Set to join a pre-created room; omit to auto-create
69        name="VideoSDK Cascaded Agent",
70        playground=True
71    )
72
73    return JobContext(room_options=room_options)
74
75if __name__ == "__main__":
76    job = WorkerJob(entrypoint=start_session, jobctx=make_context)
77    job.start()
78

Step 4.1: Generating a VideoSDK Meeting ID

To test your agent, you need a meeting ID. Use the following curl command to generate one:
1curl -X POST \
2  -H "Authorization: Bearer YOUR_VIDEOSDK_API_KEY" \
3  https://api.videosdk.live/v1/meetings
4
This command will return a meeting ID that you can use in your application.

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 uses the agent_instructions to set its persona and capabilities.
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!")
6

Step 4.3: Defining the Core Pipeline

The CascadingPipeline is the heart of the voice agent, connecting STT, LLM, TTS, VAD, and TurnDetector. Each component plays a crucial role in processing audio and generating responses. For more details, explore the

AI voice Agent Sessions

.
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)
8

Step 4.4: Managing the Session and Startup Logic

The start_session function initializes the agent session and manages the connection lifecycle.
1async def start_session(context: JobContext):
2    agent = MyVoiceAgent()
3    conversation_flow = ConversationFlow(agent)
4    pipeline = CascadingPipeline(...)
5    session = AgentSession(agent=agent, pipeline=pipeline, conversation_flow=conversation_flow)
6    try:
7        await context.connect()
8        await session.start()
9        await asyncio.Event().wait()
10    finally:
11        await session.close()
12        await context.shutdown()
13
The make_context function sets up the room options for the agent to operate in.
1def make_context() -> JobContext:
2    room_options = RoomOptions(
3        name="VideoSDK Cascaded Agent",
4        playground=True
5    )
6    return JobContext(room_options=room_options)
7

Running and Testing the Agent

Step 5.1: Running the Python Script

Run the script using the command:
1python main.py
2

Step 5.2: Interacting with the Agent in the Playground

After running the script, find the

AI Agent playground

link in the console. Use this link to join the session and interact with your voice agent.

Advanced Features and Customizations

Extending Functionality with Custom Tools

You can extend the agent's functionality by adding custom tools using the function_tool feature, allowing for more complex interactions.

Exploring Other Plugins

Explore other STT, LLM, and TTS plugins to customize and enhance your agent's capabilities, such as the

Deepgram STT Plugin for voice agent

,

OpenAI LLM Plugin for voice agent

, and

ElevenLabs TTS Plugin for voice agent

.

Troubleshooting Common Issues

API Key and Authentication Errors

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

Audio Input/Output Problems

Check your audio device settings and ensure that the correct input and output devices are selected.

Dependency and Version Conflicts

Ensure all dependencies are installed with compatible versions. Use a virtual environment to manage them effectively.

Conclusion

Summary of What You've Built

In this tutorial, you've built a CRM-integrated AI Voice Agent capable of handling customer interactions efficiently.

Next Steps and Further Learning

Explore additional features, plugins, and customizations to enhance your agent's capabilities and integrate it further into your CRM systems.

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