Voice AI

LiveKit Tutorial: Build an AI Voice Agent From Scratch (2026)

A hands-on, senior-engineer walkthrough of building a real-time AI voice agent on LiveKit — architecture, code structure, latency tuning, and deployment.

Written by

Akash Maurya

July 15, 2026
16 min read
LiveKit Tutorial: Build an AI Voice Agent From Scratch (2026)
Voice AI
Read article

Most LiveKit tutorials stop at 'hello world' — an agent that echoes back what you said. That's not useful for shipping something real. This walkthrough goes further: defining tools the agent can call, handling barge-in properly, connecting a phone number via SIP, and deploying to LiveKit Cloud with an understanding of what you're actually being billed for.

This tutorial builds a real, deployable voice agent on LiveKit from an empty project — covering the Agents framework, STT/LLM/TTS wiring, tool calling, interruption handling, telephony hookup, and the deployment and cost details that most tutorials skip.

Prerequisites and Project Setup

You'll need a LiveKit Cloud account (the free Build tier is enough for this tutorial), API keys for a speech-to-text provider (Deepgram), an LLM provider (OpenAI), and a TTS provider (Deepgram Aura-2, Cartesia, or ElevenLabs). Node.js 18+ or Python 3.9+ both work — this tutorial uses Python for the agent worker since it's the more common choice in production LiveKit deployments today.

Install the SDK

pip install livekit-agents livekit-plugins-deepgram livekit-plugins-openai livekit-plugins-silero — this pulls in the core Agents framework plus the STT, LLM, and voice-activity-detection plugins you'll wire together.

Step 1: Define the Agent

A LiveKit agent is a worker process that joins a room and runs a voice pipeline. The core building block is an AgentSession, which wires together VAD (to detect when someone is speaking), STT, the LLM, and TTS into one coordinated loop. This is the piece that handles interruption logic for you — when the user starts talking while the agent is speaking, the session automatically stops TTS output and reprocesses the new input, which is the single hardest thing to get right if you build this from scratch.

Step 2: Give the Agent Tools

A voice agent that can only talk isn't useful for business automation — it needs to take actions. LiveKit Agents lets you register Python functions as tools the LLM can call mid-conversation, the same function-calling pattern used in text-based LLM apps. For a restaurant or receptionist use case, this is where check_availability(), book_appointment(), or transfer_call() live.

The critical engineering discipline here: write tight, unambiguous docstrings for each tool. The LLM decides when to call a tool based on the description you give it — vague descriptions cause it to either call the wrong tool or hallucinate parameters instead of asking a clarifying question.

Step 3: Handle Turn Detection Properly

The default voice-activity-detection approach (Silero VAD) works on silence gaps, but it struggles with natural pauses mid-sentence ('I want to book a table for... let me check... four people'). For production quality, pair it with a turn-detection-aware STT model like Deepgram Flux, which is trained specifically to distinguish a mid-thought pause from an actual end of turn. This single change is usually the biggest perceived-quality improvement you can make to a voice agent.

Step 4: Connect a Real Phone Number

LiveKit has native SIP support, which means you can route an inbound phone number (via Twilio, Telnyx, or LiveKit's own phone number product) directly into a room your agent joins — the same agent code that worked in a browser demo now answers real phone calls with no architecture changes. This is the step that turns a tutorial project into an actual product.

Step 5: Deploy to Production

For production, deploy your agent worker to LiveKit Cloud's managed agent hosting rather than running it as a long-lived process you manage yourself — this gets you auto-scaling, observability (transcripts, trace spans, logs per session), and avoids cold-start issues that plague self-managed deployments. LiveKit Cloud's Build tier is free for prototyping; production traffic needs at minimum the Ship tier ($50/month) to avoid hard usage caps.

Latency Budget: What to Actually Tune

ComponentTypical LatencyWhat Moves the Needle
STT (streaming)150–300msDeepgram Flux/Nova-3 over batch models
LLM time-to-first-token200–500msSmaller/faster models (GPT-4o-mini, Groq-hosted Llama)
TTS time-to-first-audio150–300msStreaming TTS (Cartesia, ElevenLabs Flash) over non-streaming
Network/media transport20–80msLiveKit's global edge network, minimal by default

Pro Tip

Target under 800ms total round-trip for a conversation that feels natural. If you're consistently above 1.2 seconds, callers will start talking over the agent — that's the threshold where 'AI voice agent' starts to feel like a bad IVR again.

Cost of Running This in Production

On LiveKit Cloud, agent session minutes are billed at $0.01/min on top of the plan's included allotment, WebRTC minutes at roughly $0.0004-0.0005/min, and SIP/telephony minutes at $0.003-0.004/min. Add Deepgram STT (~$0.0048-0.0077/min), an LLM (roughly $0.005-0.02/min depending on model and conversation length), and TTS (roughly $0.01-0.07/min depending on provider). A realistic all-in cost for a GPT-4o-mini + Deepgram + Cartesia stack lands around $0.04-0.08 per minute at moderate volume — before any LiveKit plan minimums.

Implementation Checklist

  • Prototype in a browser room before wiring up telephony — isolate voice pipeline bugs from SIP/telephony bugs
  • Write explicit, narrow tool docstrings — this is the #1 lever for reducing hallucinated tool calls
  • Swap in a turn-detection-aware STT model before going to production, not after
  • Load test with simulated concurrent calls at your expected peak, not average volume
  • Set up LiveKit Cloud's observability dashboard before launch, not after your first incident
  • Confirm your LiveKit plan tier supports the compliance requirements you need (HIPAA is Scale-tier and above)

Common Mistakes

  • Building the interruption/turn-taking logic from scratch instead of using the Agents framework's built-in handling
  • Using a non-streaming TTS model, which adds 1-2+ seconds of dead air before the agent starts speaking
  • Deploying directly to Twilio without going through LiveKit's SIP layer, losing the framework's session management
  • Skipping the Ship-tier upgrade and hitting hard usage caps mid-launch on the free Build tier
  • Not testing what happens when a tool call fails (e.g., calendar API times out) — the agent needs a graceful fallback line, not silence

FAQs

Do I need Python, or can I use Node.js?

Both are officially supported by the LiveKit Agents framework. Python has slightly broader plugin coverage as of 2026; Node.js/TypeScript is a strong choice if your existing backend is already JS-based.

Can I self-host instead of using LiveKit Cloud?

Yes — the LiveKit media server and Agents framework are fully open source (Apache 2.0) and can run on your own infrastructure. This makes sense once you're past roughly 5-10 million minutes/month or have strict data-residency requirements.

How do I add a second language?

Swap the STT/TTS provider or model based on detected language, and adjust the LLM system prompt accordingly — LiveKit's plugin architecture makes this a configuration change, not a rearchitecture.

Problem

Building a real-time voice agent from raw WebRTC primitives is genuinely hard — you're dealing with audio buffering, voice activity detection, turn-taking, interruption handling, and orchestrating three separate AI services (STT, LLM, TTS) with strict latency budgets, all while keeping a stable media connection. Most teams either underestimate this complexity and ship something that talks over users, or over-invest building infrastructure LiveKit already solved.

Solution

LiveKit's Agents framework abstracts the real-time media plumbing — VAD, turn detection, interruption handling, and the STT-LLM-TTS pipeline — behind a clean Python or Node.js API, so engineering effort goes into the actual conversation logic and tool integrations instead of reimplementing WebRTC audio handling.

Key Features

  • Open-source Agents framework (Python and Node.js)
  • Pluggable STT/LLM/TTS — swap providers without rearchitecting
  • Built-in interruption and turn-detection handling
  • Native SIP/telephony support for phone-based agents
  • LiveKit Cloud for managed hosting, or self-host the media server
  • Built-in observability: transcripts, traces, and session logs

Results

  • Typical time to a working prototype: 1-2 days for an experienced engineer
  • Sub-second round-trip latency achievable with the right model selection
  • Same codebase scales from a browser demo to a production phone line

Technologies Used

LiveKitDeepgramOpenAINode.jsPython

Tags

#LiveKit#Tutorial#Voice Agent#Node.js#Python

About the Author

Written by Akash Maurya.
Published on July 15, 2026 • Updated on July 15, 2026

Keep Reading

Related Articles

AI Voice Agent System
Voice AI

How to Build an AI Voice Agent Using LiveKit and OpenAI

Learn how AI voice agents automate business calls using modern AI tools.

July 2, 2026
8 min read
Read Article
AI Voice Agent taking a restaurant reservation call
Voice AI

AI Voice Agent for Restaurants: The Complete 2026 Implementation Guide

A senior engineer's field guide to deploying AI phone agents that take reservations, answer menu questions, and stop restaurants from losing money on missed calls.

July 15, 2026
13 min read
Read Article
AI Receptionist answering front desk calls
Voice AI

AI Receptionist: How AI Is Replacing the Front Desk in 2026

A practical look at how AI receptionists work, where they genuinely outperform humans, where they don't, and how to deploy one without breaking the guest or customer experience.

July 15, 2026
12 min read
Read Article
Let's Work Together

Need an AI Solution for Your Business?

I build modern AI Voice Agents, SaaS platforms, automation systems, and full-stack applications that help businesses automate operations and improve customer experiences.