Voice Agent Frameworks: LiveKit & Pipecat
“Don’t build the phone network. Just build the app.”
TL;DR
Do not build WebRTC from scratch: it involves NAT traversal, codec negotiation, jitter buffers, and STUN/TURN infrastructure that will consume months of engineering time. Instead, use LiveKit (open-source Go SFU) for the network layer: your agent joins a “Room” as a headless participant, subscribes to the human’s microphone track, and publishes audio responses. For the AI pipeline, Pipecat (Python, by Daily) orchestrates VAD/STT/LLM/TTS using a Frame-based streaming model with automatic interruption handling. To connect to phone lines, SIP trunking via Twilio or a similar carrier bridges the PSTN to your WebRTC room, so the agent code barely changes. For teams without DevOps, turnkey solutions like Vapi and Retell offer 5-minute setup but sacrifice customization. These frameworks build on the voice agent architecture and rely heavily on Voice Activity Detection for turn-taking.

1. Introduction: The WebRTC Nightmare
Simple WebSocket pipelines work for server-to-server or simple hobby apps. But if you want to run a Voice Agent in a browser (Chrome/Safari), connect to a Telephone Line (SIP), or handle bad 4G connections, you enter the world of WebRTC (Web Real-Time Communication).
Why WebRTC is Hard (The “DIY” Trap):
- UDP vs TCP: Real-time audio uses UDP (fire-and-forget). If you lose a packet, you don’t re-transmit (it causes lag). You continue. But browsers default to TCP/HTTP.
- NAT Traversal (The “Hello, can you hear me?” problem):
- Your server has a Public IP (e.g., AWS).
- The user is behind a home router with a Private IP (
192.168.1.5). - The router blocks incoming UDP packets by default.
- Solution: You need STUN (Session Traversal Utilities for NAT) servers to tell the user their own public IP. If that fails (Symmetric NAT), you need TURN (Traversal Using Relays around NAT) servers to relay all data through a middleman. Maintaining global TURN infrastructure is expensive and hard.
- Codecs and Negotiation: Browsers speak Opus over WebRTC. A phone line arriving over SIP usually speaks G.711 (PCMU/PCMA) at 8 kHz. Something has to negotiate codecs and transcode between them in real time.
- Jitter Buffers: Packets arrive out of order. You need a buffer to reassemble audio smoothly without “Robot Voice” artifacts.
Do not write raw WebRTC logic unless you are Google or Zoom. Use an Infrastructure-as-a-Service.
2. The Infrastructure Layer: LiveKit
LiveKit is an open-source project (written in Go) that acts as a scalable SFU (Selective Forwarding Unit). It solves the plumbing.
2.1 Concepts
- Room: A virtual space. Users join a room.
- Participant: A user (Human) or an Agent (Bot).
- Track: A stream of media (Audio Track, Video Track).
- Publication/Subscription: Participants Publish tracks. Others Subscribe to them.
2.2 The Agent Architecture
LiveKit introduces a paradigm shift.
- Traditional: The Server “polls” the client.
- LiveKit: The Agent connects to the Room just like a User. It is a “Headless Client”.
- When a Human joins, the Agent subscribes to their microphone track.
- The Agent processes audio.
- The Agent publishes its replies on its own audio track.
Benefit: This automatically handles Multi-User. You can have 1 Human + 1 Agent. Or 5 Humans + 1 Agent (Conference Call Agent). Or 1 Human + 5 Agents (Simulated Boardroom). The networking logic remains the same.
LiveKit also ships its own agent framework, LiveKit Agents (Python and Node.js), which runs the STT, LLM and TTS loop and turn detection inside the room. If you are already on LiveKit, compare it with Pipecat before adding a second framework.
3. The Application Framework: Pipecat
While LiveKit handles the Network, you still need to write the Pipeline Logic (VAD -> STT -> LLM -> TTS). Pipecat (by Daily) is an open-source Python library specifically for orchestrating these pipelines.
3.1 The “Frame” Concept
Pipecat treats data as a stream of Frames.
InputAudioRawFrame/OutputAudioRawFrame(raw PCM audio in and out).TranscriptionFrame(text from STT) andLLMTextFrame(streamed text from the LLM).UserStartedSpeakingFrame,InterruptionFrame(control signals).
3.2 The Pipeline
You define an ordered list of processors. Frames flow through them like a Unix pipe, and each processor runs asynchronously.
graph LR
In(WebRTC input) --> STT(Deepgram)
STT --> User(User aggregator + VAD)
User --> LLM(OpenAI)
LLM --> TTS(ElevenLabs)
TTS --> Out(WebRTC output)
Out --> Bot(Assistant aggregator)
3.3 Pipecat Code Walkthrough
# A minimal Pipecat voice bot, written against pipecat-ai 1.15 (October 2026).
# Pipecat's API changes often: check the official quickstart before copying.
# pip install "pipecat-ai[daily,deepgram,openai,elevenlabs,silero]"
import asyncio
import os
from pipecat.audio.vad.silero import SileroVADAnalyzer
from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.worker import PipelineWorker
from pipecat.processors.aggregators.llm_context import LLMContext
from pipecat.processors.aggregators.llm_response_universal import (
LLMContextAggregatorPair,
LLMUserAggregatorParams,
)
from pipecat.services.deepgram.stt import DeepgramSTTService
from pipecat.services.elevenlabs.tts import ElevenLabsTTSService
from pipecat.services.openai.llm import OpenAILLMService
from pipecat.transports.daily.transport import DailyParams, DailyTransport
from pipecat.workers.runner import WorkerRunner
async def main():
# 1. Transport layer (the phone line): the bot joins a Daily room as a participant.
# Pipecat also has LiveKit, WebSocket and telephony transports.
transport = DailyTransport(
room_url=os.environ["DAILY_ROOM_URL"],
token=os.getenv("DAILY_TOKEN"),
bot_name="Assistant",
params=DailyParams(audio_in_enabled=True, audio_out_enabled=True),
)
# 2. Services (the organs)
stt = DeepgramSTTService(api_key=os.environ["DEEPGRAM_API_KEY"])
llm = OpenAILLMService(
api_key=os.environ["OPENAI_API_KEY"],
settings=OpenAILLMService.Settings(
system_instruction="You are a helpful voice assistant. Keep answers short.",
),
)
tts = ElevenLabsTTSService(
api_key=os.environ["ELEVENLABS_API_KEY"],
settings=ElevenLabsTTSService.Settings(voice=os.environ["ELEVENLABS_VOICE_ID"]),
)
# 3. Conversation memory. The user aggregator runs VAD, decides when the
# user's turn is over, and adds it to the context; the assistant aggregator
# records what the bot actually said (useful after an interruption).
context = LLMContext()
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
context,
user_params=LLMUserAggregatorParams(vad_analyzer=SileroVADAnalyzer()),
)
# 4. The pipeline: Mic -> STT -> context -> LLM -> TTS -> Speaker
pipeline = Pipeline([
transport.input(), # Microphone audio frames
stt, # Audio -> TranscriptionFrame
user_aggregator, # Completed user turn -> LLM request
llm, # Context -> streamed LLMTextFrames
tts, # Text -> audio frames
transport.output(), # Speaker output
assistant_aggregator, # Spoken bot reply -> context
])
# 5. Run until the pipeline ends
worker = PipelineWorker(pipeline)
runner = WorkerRunner()
await runner.add_workers(worker)
await runner.run()
if __name__ == "__main__":
asyncio.run(main())
Key Magic: Pipecat handles Interruption for you. When VAD detects the user speaking while the bot is still talking, the user aggregator broadcasts an InterruptionFrame. Downstream processors drop queued LLM text and TTS audio, so the bot stops mid-sentence, and the assistant aggregator keeps only the part of the reply that was actually spoken.
4. SIP Trunking: Asking the Agent to make a Phone Call
WebRTC is for the Internet. But businesses run on the PSTN (Public Switched Telephone Network). How do you connect your cool Python Agent to a +1-800 number?
SIP (Session Initiation Protocol) is the standard VOIP protocol.
- Buy a Number: Use Twilio or Vonage or Telnyx.
- Configure SIP Trunk: Create a SIP trunk at the provider and set its origination URI to your LiveKit project’s SIP endpoint (LiveKit Cloud gives each project one of the form
sip:<subdomain>.sip.livekit.cloud). Attach the number to that trunk. - Route the Call: In LiveKit, create an inbound trunk and a dispatch rule that decides which room each incoming call joins.
- The Bridge: When someone calls the number:
- The provider converts PSTN Audio -> SIP.
- LiveKit’s SIP service joins the caller to a room as a SIP participant.
- Your Agent sees a user join the room.
- Result: You process a phone call much like a web browser user. Expect narrowband 8 kHz audio and add telephony concerns such as DTMF and call transfer.
5. Comparison: Vapi, Bland, and Retell
If LiveKit/Pipecat is “Platform-as-a-Service” (PaaS) where you write code, there are also “Agents-as-a-Service” (SaaS).
- Vapi.ai / Retell AI:
- Model: They host the pipeline (VAD/STT/LLM/TTS). You just provide the System Prompt via API.
- Pros: Instant setup (5 mins). They handle telephony edge cases such as answering machine detection out of the box.
- Cons: Black box. Hard to customize complex logic (e.g., “If user says X, query internal SQL DB, then reply”). You have to use their “Tool Calling” webhooks which adds latency.
- Cost: A platform fee per minute on top of the STT, LLM, TTS and telephony costs. At the time of writing (November 2026), Vapi’s pricing page lists $0.05/min for hosting with model costs passed through, and Retell’s lists $0.055/min for voice infrastructure plus per-minute LLM, voice and telephony charges. These change often, so price your own call mix.
- Bland AI:
- Specialized for high-volume phone calling (outbound campaigns, support lines).
- Pros: Built around telephony scale rather than browser sessions.
Verdict:
- Use Vapi/Retell: For prototypes, simple appointment setters, or if you don’t have a DevOps team.
- Use LiveKit/Pipecat: For Core Product, complex workflows, RAG integrations, or high-scale where margin and control matter. At volume, the per-minute fee and the TTS bill dominate; self-hosting TTS is the next lever once you own the pipeline.
6. Summary
- Don’t build WebRTC from scratch. It is a black hole of engineering time.
- LiveKit creates the room and handles video/audio/screen sharing.
- Pipecat creates the bot and handles the VAD/LLM/TTS pipeline.
- SIP connects the phone network to the Agent.
These frameworks standardize the Transport Layer so you can focus entirely on the Intelligence Layer.
A critical component of these frameworks is Voice Activity Detection (VAD), the math of detecting silence.
FAQ
Q: What is LiveKit and how does it work for voice agents? A: LiveKit is an open-source SFU (Selective Forwarding Unit) written in Go that handles WebRTC infrastructure. Your AI agent joins a Room as a headless participant, subscribes to the human’s microphone track, processes audio through your pipeline, and publishes responses on its own speaker track. This architecture naturally supports multi-user scenarios.
Q: How does Pipecat orchestrate a voice agent pipeline? A: Pipecat is an open-source Python framework by Daily that treats data as a stream of Frames: audio frames, transcription and LLM text frames, and control frames such as UserStartedSpeakingFrame. You define a Pipeline as a list of processors (transport, STT, context aggregator, LLM, TTS) and frames flow through them like Unix pipes. When the user starts speaking, an InterruptionFrame cancels the bot’s queued text and audio.
Q: How do I connect an AI voice agent to a phone number? A: Use SIP trunking: buy a phone number from Twilio, Vonage, or Telnyx, then create a SIP trunk whose origination URI points to your LiveKit SIP endpoint, then add an inbound trunk and dispatch rule in LiveKit. When someone calls, the provider converts PSTN audio to SIP, LiveKit joins the caller to a room as a SIP participant, and your agent handles the call much like a browser user.
Q: Should I use Vapi/Retell or build with LiveKit/Pipecat? A: Use Vapi or Retell for prototypes, simple appointment setters, or teams without DevOps. They offer 5-minute setup but are black boxes with markup costs. Use LiveKit/Pipecat when voice is your core product, you need complex workflows or RAG integrations, or margin and control matter at scale.