gray-cartoon-87056
05/13/2026, 6:38 AMtall-airline-16756
05/13/2026, 6:39 AMtall-airline-16756
05/13/2026, 6:39 AMgray-cartoon-87056
05/13/2026, 6:53 AMtall-airline-16756
05/13/2026, 6:53 AM@livekit/agents SDK and a sample agent that subscribes to audio, streams it to STT, and publishes TTS.
• If you want agents in Python, I can show the equivalent Python agent setup and deployment steps.
Which language would you like example code for?
Sources: Introduction | LiveKit Documentation, with interactive elementsgray-cartoon-87056
05/13/2026, 6:56 AMtall-airline-16756
05/13/2026, 6:56 AMwrtc) to connect your TypeScript backend to LiveKit.
Below are concise steps, docs, and short TypeScript examples you can use.
Key docs
• Token generation & auth: https://docs.livekit.io/frontends/build/authentication/custom/
• Server SDKs (room management & tokens): https://docs.livekit.io/server/
• JS/TS client (WebRTC): https://docs.livekit.io/client-sdk/js/
1) Generate access tokens (server-side, Node/TypeScript)
• Use livekit-server-sdk to mint JWTs with room permissions.
Example:
import { AccessToken, VideoGrant } from "livekit-server-sdk";
const at = new AccessToken("API_KEY", "API_SECRET");
at.identity = "user-123";
const grant: VideoGrant = { room: "my-room", roomJoin: true, canPublish: true, canSubscribe: true };
at.addGrant(grant);
const token = await at.toJwt();
2) Room management (optional server-side control)
• Rooms are created when the first participant joins, but you can create/list/delete rooms via RoomServiceClient.
Example:
import { RoomServiceClient } from "livekit-server-sdk";
const svc = new RoomServiceClient("https://your-livekit-host", "API_KEY", "API_SECRET");
await svc.createRoom({ name: "my-room" });
3) WebRTC client (browser / Node with wrtc): connecting to LiveKit
• Use livekit-client in browser/Node. In Node you can use the wrtc package for WebRTC internals.
Browser example:
import { Room } from "livekit-client";
const room = new Room();
await room.connect("wss://your-livekit-host", token);
// publish local tracks or listen for remote audio
Node (headless) example with `wrtc`:
• Install: npm install livekit-client wrtc
import { Room, createLocalAudioTrack } from "livekit-client";
import wrtc from "wrtc";
const room = new Room({ WebRtcAdapter: { RTCPeerConnection: wrtc.RTCPeerConnection } } as any);
await room.connect("wss://your-livekit-host", token);
// create/publish an audio track (e.g., from file or mic pipeline)
const localTrack = await createLocalAudioTrack();
await room.localParticipant.publishTrack(localTrack);
4) Connecting your TypeScript backend + Agents
• Your TypeScript backend can:
◦ Generate tokens and manage rooms/webhooks.
◦ Either host Node agents using @livekit/agents or call out to Python agents — agents join rooms as participants and run STT/TTS.
• Agents can be implemented in Node/TypeScript (use @livekit/agents) or Python (official agent SDKs).
Next step
• Tell me whether you want a full example: (A) TypeScript agent that subscribes to audio + uses an STT/TTS plugin, or (B) a headless Node wrtc client that bridges your WhatsApp webhook audio into a LiveKit room. I’ll provide the code you choose., with interactive elementsgray-cartoon-87056
05/13/2026, 6:58 AMtall-airline-16756
05/13/2026, 6:59 AMstt and tts providers for that session.
• The agent processes audio in real time and publishes TTS back into the room.
Ways to pass per-call config:
• Dispatch metadata (readable by the agent when it starts).
• Token/room configuration (embed agent settings in the token).
• Programmatic agent startup (your backend calls dispatch API with config).
If you want, I can:
• Show a short example of dispatching a room with metadata and reading it inside an agent (TypeScript or Python).
• Or provide a sample AgentSession snippet that switches STT/TTS per call.
Which example would you like?
Sources: Speech-to-text (STT) models overview | LiveKit Documentation | External data and RAG | LiveKit Documentation | Layered Caller Verification for LiveKit SIP Calls | LiveKit | Agent dispatch | LiveKit Documentation | Layered Caller Verification for LiveKit SIP Calls | LiveKit, with interactive elementsgray-cartoon-87056
05/13/2026, 7:39 AMtall-airline-16756
05/13/2026, 7:40 AMgray-cartoon-87056
05/13/2026, 7:42 AMtall-airline-16756
05/13/2026, 7:43 AMlanguage="multi" or explicit language hint when known.
• Alternative / lower cost: Cartesia Ink Whisper — wide language coverage and good accuracy for low‑resource languages.
• Implementation note: stream STT (real‑time) so transcripts arrive incrementally for turn detection and LLM streaming.
TTS (recommended)
• Primary: ElevenLabs Eleven Multilingual v2 — most natural, human‑like voices across many languages; good for Tamil, English, Malay, Mandarin.
• Alternative: Rime Arcana — high quality, good multilingual switching and expressive voices if ElevenLabs isn’t suitable.
• Implementation note: prefer streaming/low‑latency TTS with eager token→audio playback and prebuffer small chunks so audio starts quickly.
LLM (recommended)
• Fast / low‑latency: OpenAI GPT‑4o or GPT‑4.1 mini (use a distilled / streaming‑friendly variant). These give low time‑to‑first‑token and stream well into TTS.
• Implementation note: choose a model that supports streaming output so TTS can start on first tokens; use smaller/distilled models for the strictest latency budgets.
RAG guidance (brief)
• RAG is recommended when you need factual, domain or user‑specific answers. It improves accuracy but adds some retrieval latency — mitigate with caching, selective retrieval, and parallel retrieval+LLM streaming.
Deployment tips for low latency
• Co‑locate agents/LLM/STT/TTS regionally near your users (reduce RTT).
• Stream at each stage (STT → partial transcript → LLM streaming → TTS streaming).
• Use smaller/distilled models for quick TTFT for routine prompts; fall back to stronger models for complex queries.
• Use language hints / VAD to reduce unnecessary processing and to trigger quicker turns.
If you want, I can:
• Provide a short AgentSession example in TypeScript or Python wiring Deepgram + GPT‑4o + ElevenLabs for these languages.
Which language (TypeScript or Python) do you prefer for the example?
Sources: Build a multilingual voice agent that automatically switches languages | Li... | Deepgram STT | LiveKit Documentation | Speech-to-text (STT) models overview | LiveKit Documentation | Building Performant Voice Agents in India | LiveKit | Build voice, video, and physical AI | LiveKit, with interactive elementsgray-cartoon-87056
05/13/2026, 7:44 AMtall-airline-16756
05/13/2026, 7:44 AMgray-cartoon-87056
05/13/2026, 7:45 AMtall-airline-16756
05/13/2026, 7:45 AMon_user_turn_started or on_user_turn_completed), make an HTTP call to your RAG endpoint, get top‑K passages, and inject them into the prompt/context before calling the LLM.
• Tool (LLM-invoked retrieval)
◦ Expose your RAG as a callable tool. Register a tool interface the LLM can call during generation; when invoked, the agent calls your endpoint, returns passages, and the LLM continues generation.
Practical notes
• Use a fast HTTP client (e.g., httpx or requests in Python). Keep responses small (top‑K, pre-summarized) to limit prompt size.
• Ensure the agent process can reach your endpoint (network, DNS, auth). If agents run in containers, allow outbound access or place the endpoint in the same VPC.
• Cache frequent queries and return source IDs for traceability.
• If you need streaming results into the LLM/TTS pipeline, return incremental snippets or call the retrieval in parallel with LLM start (prefetch + tool hybrid).
Quick Python sketch (hook style):
import httpx
async def on_user_turn_started(ctx):
query = ctx.user_utterance
async with httpx.AsyncClient(timeout=5.0) as client:
res = await client.post("https://your-rag.example/search", json={"q": query, "k": 5})
passages = res.json()["passages"]
# inject passages into system prompt or session state
ctx.session.prompt_add_context(passages)
Tell me which pattern you prefer (hook vs tool) and whether you want a full agent.py example showing the HTTP call + prompt injection (TypeScript or Python).
, with interactive elementsgray-cartoon-87056
05/13/2026, 8:26 AMtall-airline-16756
05/13/2026, 8:26 AM