m
hi
t
Thanks for reaching out, Rahib. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi — how can I help you today? What are you trying to do with LiveKit (SDK, server, authentication, rooms, recording, or something else)?
m
Are there any examples where agent can speak fluently in languages that it receives from the llm ? For example in a language learning agent it might be talking in english but as it is correcting someone it might say some words in that language.
t
You're asking if agents can speak fluently in languages they receive from an LLM — for example, a language-learning agent that speaks mostly English but inserts words or corrections in the target language. Yes — LiveKit supports that pattern and there are examples and building blocks you can reuse. What exists and how to use it • Example: the "Change Language" agent demonstrates switching the agent's output language during a session, so an agent can dynamically speak different languages. • Turn detection: the
MultilingualModel
supports mixed-language conversations (13 languages) and correctly detects turns when users and agents switch languages. • TTS support: examples use ElevenLabs TTS (and other multilingual TTS) that can be configured per segment to render the correct language and pronunciation. • Prompting pattern: prepend or include language instructions (e.g.,
en-US
or target language) in the LLM prompt so the model outputs the desired mix of English and foreign-language phrases. How you’d build a language-learning agent (high level) 1. Use an LLM that can output multilingual text and instruct it to produce corrections or target-language phrases inline with English explanations. 2. Send the LLM output to your TTS engine. For each spoken segment, set the TTS language/voice to match the text (switch dynamically when the LLM outputs target-language snippets). 3. Use the turn detector to segment user/agent turns reliably when languages switch. 4. Optionally, control pronunciation or phonetic hints via prompt instructions or by sending small phonetic fragments to a TTS engine that supports SSML/phonemes. If you want, I can: • Point you to the "Change Language" recipe and the turn-detector example. • Sketch a short prompt template that mixes English explanations and target-language corrections. Which would you like? Sources: LiveKit Docs | Building the all-in-one platform for voice AI agents | LiveKit turn detector plugin | LiveKit docs | Live Conversations with AI using ChatGPT and WebRTC
m
Can you tell me if my thinking is correct for the architecture: We have a frontend ui which uses nextjs We have a backend agent in python We can have a api app that can use fast api So basically there are three layers of framework in order to build a full stack agent? for example a fastAPI can handle db calls and all that backend agent handles the main agent logic and nextjs ui shows the UI interface ? Am i correct?
t
You're on the right track — that three-layer split is a common, sensible architecture for a full-stack agent. Quick confirmation and a few practical notes: • Frontend (Next.js) ◦ Handles UI, captures microphone/camera input, plays TTS audio, and displays transcripts/feedback. ◦ Connects to LiveKit for real-time audio/video and to your API for agent requests, session state, or transcripts. • API layer (FastAPI) ◦ Handles authentication, DB access, session/room management, and exposes endpoints the frontend calls. ◦ Orchestrates calls to external services (LLM, TTS, speech-to-text), stores conversation history, and returns structured data to the frontend. • Backend agent (Python) ◦ Implements the agent logic: prompt engineering, dialogue state, turn management, deciding when to call LLM/TTS/ASR, and post-processing. ◦ Can run as part of the FastAPI app or as a separate service that the API calls (both are valid; separate service helps scale and isolate heavy LLM work). Additional practical points • LiveKit: Use it for real-time media routing and to connect users and agent audio streams; agent can join rooms as a participant or receive media via an audio bridge/TTS integration. • Where to host LLM/TTS/ASR: these are typically called from the API or the agent service. Keep latency in mind — colocate heavy model calls near the agent service. • Scaling: separate services (API, agent worker, background job queue) make horizontal scaling and retries easier. • Security & state: keep DB, secrets, and user identity logic in the API layer; agent logic should receive only the data it needs. • Simpler option: For small projects, you can combine agent logic into the FastAPI app to reduce complexity, then split later. If you want, I can: • Sketch a minimal deployment layout (which services talk to which) or • Provide a short example flow: user speech → frontend → ASR → agent → TTS → LiveKit playback. Which would help you next?
m
• Sketch a minimal deployment layout (which services talk to which) or
t
Acknowledged — you want a minimal deployment layout showing which services talk to which. Below is a simple, focused diagram and a short explanation of each connection. Minimal deployment layout (components and connections) • Browser (Next.js UI) ◦ ↔️ LiveKit (real-time audio/video & data channels) ◦ ↔️ FastAPI (REST/WebSocket calls for auth, session metadata, transcripts, UI actions) • FastAPI (API layer) ◦ ↔️ Browser (auth, session management, DB reads/writes) ◦ ↔️ Backend Agent (RPC or HTTP calls to request agent processing) ◦ ↔️ Database (conversation history, user profiles, secrets) ◦ ↔️ LiveKit Admin API (create/join rooms, tokens) • Backend Agent (Python service) ◦ ↔️ FastAPI (receives requests to run agent logic) ◦ ↔️ LLM provider (generate responses / corrections) ◦ ↔️ ASR provider (optional: transcribe audio if not using LiveKit pipeline) ◦ ↔️ TTS provider (synthesize agent speech; can return audio stream or files) ◦ ↔️ Storage/DB (optional: store transcripts, artifacts) • LiveKit (media routing) ◦ ↔️ Browser (publish/subscribe audio & video) ◦ ↔️ Backend Agent or TTS gateway (agent can join as a participant or receive/send audio via a bridge) • External services ◦ LLM, ASR, TTS providers called by Backend Agent (or FastAPI if agent is co-located) Flow examples (short) 1. Real-time voice flow: ◦ User speaks → Browser publishes audio to LiveKit → Agent subscribes to audio (or FastAPI pulls recorded chunks) → Agent calls ASR → Agent calls LLM → Agent calls TTS → Agent publishes synthesized audio back into LiveKit → Browser plays agent audio. 1. API-driven flow (low-latency text interactions or control): ◦ Browser sends message → FastAPI → Backend Agent (LLM) → FastAPI returns structured response → Browser displays text or triggers TTS. Deployment notes (concise) • The Backend Agent can be co-located inside FastAPI for simplicity; split into a separate service for better scaling. • Use LiveKit for real-time media; agent can either join rooms as a participant or receive media via a bridge. • Keep DB and secrets behind FastAPI; only expose necessary tokens to the client. • Place LLM/TTS close to the agent service to reduce latency. Would you like a sample sequence diagram for the real-time voice flow or a minimal file list for deploying these services?