LiveKit Agents is the most common way teams ship production voice agents in 2026: your agent joins a LiveKit room as a participant, WebRTC handles the media transport, and the AgentSession class wires together voice activity detection, speech-to-text, an LLM, and text-to-speech into a single turn-taking loop. This is a working tutorial for standing up a bilingual Arabic/English voice agent on LiveKit using Hakim for STT and TTS, from an empty repo to a working call.
What you're building
A LiveKit Agents worker that:
- Joins a room and listens for a participant
- Transcribes their speech with Hakim Arab v2 (dialect-aware, code-switching)
- Passes the transcript to an LLM of your choice
- Speaks the response back with Hakim Saree' v1.3 (sub-120 ms TTFB)
- Handles interruptions (barge-in) so the caller can cut the agent off mid-sentence
This is the same shape as any LiveKit voice agent; the only Hakim-specific pieces are the STT and TTS plugin classes.
Prerequisites
- A LiveKit Cloud project or self-hosted LiveKit server
- Python 3.10+
- A Hakim API key (free tier covers this tutorial, sign up at tryhakim.ai)
- An LLM API key (OpenAI, Anthropic, or your own endpoint)
Install
pip install livekit-agents livekit-plugins-silero hakim-livekit
hakim-livekit is Hakim's official LiveKit plugin (github.com/tryHakimAI/hakim-livekit) and exposes HakimSTT and HakimTTS, both conforming to LiveKit's plugin interfaces so they drop into AgentSession like any other provider's plugin.
The agent
import os
from livekit.agents import AgentSession, Agent, JobContext, WorkerOptions, cli
from livekit.plugins import silero, openai
from hakim_livekit import HakimSTT, HakimTTS
async def entrypoint(ctx: JobContext):
await ctx.connect()
session = AgentSession(
vad=silero.VAD.load(),
stt=HakimSTT(
api_key=os.environ["HAKIM_API_KEY"],
language="ar", # or "auto" for code-switching callers
),
llm=openai.LLM(model="gpt-4o-mini"),
tts=HakimTTS(
api_key=os.environ["HAKIM_API_KEY"],
voice="hakim-preset-khaleeji-male-1",
),
)
await session.start(
agent=Agent(instructions="You are a helpful assistant. Reply in the caller's language."),
room=ctx.room,
)
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Run it with python agent.py dev and connect to a test room from LiveKit's Agents Playground. That's a complete bilingual voice agent, no custom audio handling, no manual WebSocket wiring.
What HakimSTT and HakimTTS actually do
Both plugins wrap Hakim's real-time WebSocket endpoints, not the batch REST API, so they:
- Stream partial transcripts to the LLM as the caller is still talking (interim results), so the agent can start reasoning before the caller finishes their turn
- Stream TTS audio back in ~50-80 ms frames, matching LiveKit's own frame-based audio pipeline
- Surface Hakim's dialect detection as a field on the transcript event, which you can log or route on (useful if you want to pick a matching-dialect TTS voice per caller)
Turn detection and interruptions
LiveKit's AgentSession handles voice activity detection (via the Silero VAD plugin) and turn-taking automatically: when the caller starts speaking while the agent is mid-response, the session cancels the in-flight TTS and LLM calls and starts listening. This works out of the box with HakimTTS because the plugin honors LiveKit's cancellation signal and stops generating new audio frames within LiveKit's cancellation window. It doesn't keep the old response queued up behind the new turn.
If your agent needs custom turn-detection logic (for example, waiting slightly longer before interrupting on a caller who pauses mid-sentence in Arabic, where clause-final pauses are longer than in English), LiveKit exposes a turn_detector plugin slot. This is worth tuning for Arabic specifically: a turn-detection model trained mostly on English speech will fire early on Arabic callers more often than it should, because it's reading pause length against English cadence norms.
Picking a voice
Hakim ships preset voices per dialect family (Khaleeji, Egyptian, Levantine, MSA) plus cloning if you need a branded voice. For a support agent, matching the caller's detected dialect to a preset voice from the same family measurably improves perceived naturalness over a single default voice. Pull the dialect field off the STT transcript event and switch HakimTTS's voice parameter per-turn if you want this behavior; the plugin supports mid-session voice changes without reconnecting.
Multi-participant rooms
LiveKit's room model means the agent isn't restricted to one-on-one calls. You can join multiple human participants (a supervised handoff scenario, or a group call where the agent only responds when addressed) into the same room as the agent. HakimSTT transcribes each participant's track independently, so you can build routing logic ("only respond to the participant who said the wake phrase") on top without needing a separate mixing step.
Production checklist
Before shipping this to real callers:
- Set
language="auto"if your callers regularly code-switch between Arabic and English mid-sentence. The plugin re-detects per utterance rather than locking to whatever it heard first. - Instrument TTFB on the TTS side and STT partial-result latency on the transcription side separately; they have different failure modes and you want to know which one degraded if a call feels slow.
- Test barge-in with a real caller, not a scripted turn-taking demo. Arabic conversational cadence has different interruption patterns than the English test scripts most turn-detection models were tuned against.
- If you're deploying for EU or GCC customers, check Hakim's region list. Data residency requirements are usually easier to satisfy by picking the right inference region up front than by migrating after launch.
The full example, including error handling and a Dockerfile for deployment, is in the hakim-livekit repo under examples/. If you're deciding between LiveKit and another framework for your next agent, we wrote a framework comparison covering LiveKit, Pipecat, and Vapi side by side.