Introduction to AI Voice Agents in Recruitment
AI Voice Agents are transforming industries by automating interactions and providing real-time assistance. In the recruitment industry, these agents streamline processes by answering queries, scheduling interviews, and offering guidance to candidates and recruiters alike. This tutorial will guide you through building an AI Voice Agent tailored for recruitment using the VideoSDK framework.
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 integrates technologies like Speech-to-Text (STT), Text-to-Speech (TTS), and Natural Language Processing (NLP) to facilitate seamless communication.
Why are they important for the recruitment industry?
In recruitment, AI Voice Agents can handle repetitive tasks, provide instant responses to candidate queries, and assist recruiters by managing schedules and reminders. This automation leads to increased efficiency and allows human recruiters to focus on more strategic tasks.
Core Components of a Voice Agent
- STT (Speech-to-Text): Converts spoken language into text.
- LLM (Large Language Model): Processes text and generates responses.
- TTS (Text-to-Speech): Converts text responses back into speech.
For a detailed understanding of these components, refer to the
AI voice Agent core components overview
.What You'll Build in This Tutorial
In this tutorial, you'll create a fully functional AI Voice Agent for recruitment. The agent will interact with users, provide information, and manage interview schedules.
Architecture and Core Concepts
High-Level Architecture Overview
The AI Voice Agent's architecture involves converting user speech into text, processing the text to generate a response, and converting the response back to speech. This process is managed by a
cascading pipeline in AI voice Agents
that integrates various plugins for each task.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->>Agent: Speech
14 Agent->>User: Respond
15Understanding Key Concepts in the VideoSDK Framework
- Agent: The core class representing your bot.
- CascadingPipeline: Manages the flow of audio processing from STT to LLM to TTS.
- VAD & TurnDetector: These components help the agent determine when to listen and when to speak.
Setting Up the Development Environment
Prerequisites
Before you begin, ensure you have Python 3.11+ installed and a VideoSDK account. Sign up at app.videosdk.live to access the API keys required for this tutorial.
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`
3Step 2: Install Required Packages
Install the necessary packages using pip:
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 keys:1VIDEOSDK_API_KEY=your_api_key
2VIDEOSDK_SECRET_KEY=your_secret_key
3Building the AI Voice Agent: A Step-by-Step Guide
Here's the complete code to create your 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 knowledgeable and efficient AI Voice Agent specialized in the recruitment industry. Your primary role is to assist recruiters and job seekers by providing information and guidance throughout the recruitment process. You can answer questions about job openings, application procedures, interview tips, and company culture. Additionally, you can schedule interviews and send reminders to candidates. However, you are not a human recruiter and cannot make hiring decisions or provide personalized career advice. Always remind users to consult with a human recruiter for personalized guidance and final decisions. Your responses should be concise, informative, and professional, ensuring a seamless experience for both recruiters and candidates."
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()
63Now, let's break down the code to understand each component.
Step 4.1: Generating a VideoSDK Meeting ID
To interact with your agent, you'll need a meeting ID. Use the following
curl command to generate one:1curl -X POST "https://api.videosdk.live/v1/meetings" -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
2Step 4.2: Creating the Custom Agent Class
The
MyVoiceAgent class defines the behavior of your agent. It inherits from Agent and initializes with specific instructions for handling recruitment-related queries.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 is the backbone of your agent, orchestrating the flow of data through various plugins. For more details, you can explore the Voice Agent Quick Start Guide
.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's session, connecting to the VideoSDK service and handling cleanup.1async def start_session(context: JobContext):
2 agent = MyVoiceAgent()
3 conversation_flow = ConversationFlow(agent)
4 pipeline = CascadingPipeline(
5 stt=DeepgramSTT(model="nova-2", language="en"),
6 llm=OpenAILLM(model="gpt-4o"),
7 tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
8 vad=SileroVAD(threshold=0.35),
9 turn_detector=TurnDetector(threshold=0.8)
10 )
11 session = AgentSession(
12 agent=agent,
13 pipeline=pipeline,
14 conversation_flow=conversation_flow
15 )
16 try:
17 await context.connect()
18 await session.start()
19 await asyncio.Event().wait()
20 finally:
21 await session.close()
22 await context.shutdown()
23Running and Testing the Agent
Step 5.1: Running the Python Script
Run your script with:
1python main.py
2Step 5.2: Interacting with the Agent in the Playground
After starting the agent, you'll see a
playground
link in the console. Open this link in a browser to interact with your agent.Advanced Features and Customizations
Extending Functionality with Custom Tools
Enhance your agent by integrating custom tools to handle specific tasks, such as parsing resumes or providing detailed job descriptions.
Exploring Other Plugins
Experiment with different plugins for STT, LLM, and TTS to optimize performance and cost. Consider using the
ElevenLabs TTS Plugin for voice agent
and theDeepgram STT Plugin for voice agent
for enhanced capabilities.Troubleshooting Common Issues
API Key and Authentication Errors
Ensure your API keys are correctly set in the
.env file and that your VideoSDK account is active.Audio Input/Output Problems
Check your microphone and speaker settings if you encounter issues with audio input or output.
Dependency and Version Conflicts
Ensure all dependencies are up-to-date and compatible with Python 3.11+.
Conclusion
Summary of What You've Built
You've built an AI Voice Agent capable of assisting in the recruitment process, providing information, and managing schedules. The
AI voice Agent Sessions
provide a robust framework for managing interactions.Next Steps and Further Learning
Explore additional features and plugins to further enhance your agent's capabilities and efficiency. Consider integrating the
OpenAI LLM Plugin for voice agent
andSilero Voice Activity Detection
to improve interaction quality.Want to level-up your learning? Subscribe now
Subscribe to our newsletter for more tech based insights
FAQ