Build an AI Voice Assistant for Recruitment

Discover how to create an AI voice assistant for recruitment using VideoSDK, complete with step-by-step instructions and code.

Introduction to AI Voice Agents in Recruitment

AI Voice Agents are intelligent systems capable of understanding and responding to human speech. These agents utilize technologies like Speech-to-Text (STT), Language Learning Models (LLM), and Text-to-Speech (TTS) to interact with users in a natural and conversational manner. In the recruitment industry, AI Voice Agents play a crucial role by assisting recruiters in tasks such as candidate screening, interview scheduling, and providing insights into recruitment trends.

Why are they important for the recruitment industry?

AI Voice Agents streamline the recruitment process by automating repetitive tasks, allowing recruiters to focus on more strategic activities. They can provide quick responses to common queries, offer tips on candidate engagement, and deliver updates on industry best practices.

Core Components of a

Voice Agent

  • Speech-to-Text (STT): Converts spoken language into text.
  • Language Learning Model (LLM): Understands and processes the text to generate appropriate responses.
  • Text-to-Speech (TTS): Converts the text response back into spoken language.
  • AI voice Agent core components overview

    :
    Provides a detailed look at the essential building blocks of AI voice agents.

What You'll Build in This Tutorial

In this tutorial, you'll learn how to build a voice assistant tailored for the recruitment industry using the VideoSDK framework. We'll cover everything from setting up your development environment to deploying a fully functional AI

Voice Agent

.

Architecture and Core Concepts

High-Level Architecture Overview

The architecture of an AI

Voice Agent

involves a seamless flow of data from user speech to agent response. The process begins with capturing the user's voice, converting it into text, processing the text to generate a response, and finally converting the response back into speech.
Diagram

Understanding Key Concepts in the VideoSDK Framework

  • Agent: The core class representing your bot, responsible for managing interactions.
  • Cascading pipeline in AI voice Agents

    :
    The flow of audio processing, integrating STT, LLM, and TTS.
  • VAD & TurnDetector: These components help the agent determine when to listen and when to speak.

Setting Up the Development Environment

Prerequisites

To get started, ensure you have Python 3.11+ installed and a VideoSDK account at app.videosdk.live.

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`
3

Step 2: Install Required Packages

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

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

Here is the complete, runnable 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 knowledgeable recruitment industry assistant. Your primary role is to assist recruiters by providing information on recruitment processes, candidate screening, and interview scheduling. You can answer questions about best practices in recruitment, provide tips on candidate engagement, and offer insights into industry trends. However, you are not a certified HR professional, and you must advise users to consult with a qualified HR expert for legal or compliance-related queries. You should also refrain from making any hiring decisions or providing personal opinions on candidates. Your responses should be concise, informative, and aligned with the latest recruitment industry standards."
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()
63

Step 4.1: Generating a VideoSDK Meeting ID

To generate a meeting ID, use the following curl command:
1curl -X POST "https://api.videosdk.live/v1/meetings" \
2-H "Authorization: Bearer YOUR_API_KEY" \
3-H "Content-Type: application/json"
4

Step 4.2: Creating the Custom Agent Class

The MyVoiceAgent class extends the Agent class. It initializes with specific instructions tailored for the recruitment industry, ensuring the agent provides relevant and accurate information.
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 integrates various plugins to process audio data. Each component has a specific role:
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 manages the agent's lifecycle. It connects to the VideoSDK service, starts the session, and ensures resources are cleaned up after use.
1async def start_session(context: JobContext):
2    # Create agent and conversation flow
3    agent = MyVoiceAgent()
4    conversation_flow = ConversationFlow(agent)
5
6    # Create pipeline
7    pipeline = CascadingPipeline(
8        stt=DeepgramSTT(model="nova-2", language="en"),
9        llm=OpenAILLM(model="gpt-4o"),
10        tts=ElevenLabsTTS(model="eleven_flash_v2_5"),
11        vad=SileroVAD(threshold=0.35),
12        turn_detector=TurnDetector(threshold=0.8)
13    )
14
15    session = AgentSession(
16        agent=agent,
17        pipeline=pipeline,
18        conversation_flow=conversation_flow
19    )
20
21    try:
22        await context.connect()
23        await session.start()
24        # Keep the session running until manually terminated
25        await asyncio.Event().wait()
26    finally:
27        # Clean up resources when done
28        await session.close()
29        await context.shutdown()
30
The make_context function sets up the room options, enabling the agent to operate in a playground environment for testing:
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
The if __name__ == "__main__": block starts the agent:
1if __name__ == "__main__":
2    job = WorkerJob(entrypoint=start_session, jobctx=make_context)
3    job.start()
4

Running and Testing the Agent

Step 5.1: Running the Python Script

Run the script using:
1python main.py
2

Step 5.2: Interacting with the Agent in the Playground

After starting the agent, find the playground link in the console. Join the session to interact with your AI Voice Agent. Use Ctrl+C to gracefully shut down the session.

Advanced Features and Customizations

Extending Functionality with Custom Tools

Enhance your agent by integrating custom tools for specific tasks, such as data retrieval or advanced analytics.

Exploring Other Plugins

Explore other plugins for STT, LLM, and TTS to further customize your agent's capabilities.

Troubleshooting Common Issues

API Key and Authentication Errors

Ensure your API keys are correctly configured in the .env file.

Audio Input/Output Problems

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

Dependency and Version Conflicts

Ensure all dependencies are up-to-date and compatible with your Python version.

Conclusion

Summary of What You've Built

You've successfully built an AI Voice Agent for the recruitment industry, capable of assisting with various recruitment tasks.

Next Steps and Further Learning

Explore more advanced features of the VideoSDK framework and consider integrating additional plugins to enhance your agent's functionality.

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