Prerequisites
- Python 3.8+
- LiveKit server credentials (URL, API key, secret)
- Tavily API key (for web search tool)
- Google Cloud credentials (for Gemini LLM and voice)
- Maxim account (API key, log repo ID)
Project Setup
Configure your environment variables in .env:Install Dependencies
Add Dependencies to requirements.txt
Set Up a Virtual Environment
Create a Project Directory and Navigate into It
Code Walkthrough: Key Components
Below, each section of the code is presented with a technical explanation.1. Imports and Initialization
Explanation:
- Imports all required libraries for real-time audio, AI agent orchestration, logging, and web search.
- Loads environment variables and configures logging for debugging and traceability.
- Initializes the Maxim logger and retrieves the Tavily API key for web search functionality.
2. Maxim Event Instrumentation
Explanation:
Defines a callback to log when Maxim traces start and end, providing visibility into the agent’s lifecycle. instrument_livekit integrates Maxim with LiveKit, ensuring all relevant events are captured for observability.3. InterviewAgent Class
Explanation:
- Defines the main agent class, which is initialized with a Job Description (JD) and uses it to guide the interview.
- The web_search method is exposed as a tool, allowing the agent to perform real-time web searches using Tavily.
- Handles missing API keys and exceptions gracefully, returning informative error messages.
- Focus on the System Instructions provided, you can modify it as per your requirements (incase you are building an agent for some other usecase) -
4. Entrypoint: Starting the Interview Session
Explanation:
- Prompts the user for a Job Description and creates a new LiveKit room for the interview session.
- Initializes the agent session with the provided JD and configures the LLM and TTS voice.
- Prints a join link for the user to access the interview room in their browser.
- Ensures proper cleanup of resources after the session ends.
5. Main Block
Explanation:
Entry point for the script. Configures the worker options and launches the agent using the provided entry point function.How to Use
- Paste your JD: The agent will use it to generate relevant interview questions.
- Room is created: A join link is printed, open it in your browser to join the interview room or you can also trigger the voice agent via the console as we are doing in the below video.
- Interact with the AI interviewer:
- Your voice is transcribed (STT)
- Gemini LLM processes and generates responses
- Monitor in Maxim:
- All prompts, responses, and events are logged for review and debugging
Run the Script
Observability with Maxim
Every action, prompt, and web search is logged in your Maxim dashboard. Use Maxim to debug, audit, and improve your agent’s performance.Troubleshooting
- No audio or agent is silent
- Check your Google Cloud credentials
- Confirm browser and microphone permissions
- Web search not working
- Ensure your TAVILY_API_KEY is set in .env
- No Maxim traces
- Ensure your MAXIM_API_KEY is set in .env