polite-dog-12152
09/09/2025, 6:52 AMtall-airline-16756
09/09/2025, 6:52 AMtall-airline-16756
09/09/2025, 6:53 AMpolite-dog-12152
09/09/2025, 6:55 AMtall-airline-16756
09/09/2025, 6:55 AMconst agent = new pipeline.VoicePipelineAgent(
vad,
new deepgram.STT(),
new openai.LLM(),
new elevenlabs.TTS(),
{ chatCtx: initialContext }
);
agent.start(ctx.room, participant);
await agent.say('Hey, how can I help you today', true);
This setup configures the agent with VAD, STT, LLM, and TTS models, and it kicks off the interaction as soon as a participant joins the room.
LiveKit also offers examples in both Python and Node.js, and supports integrations with providers like Deepgram, OpenAI, and ElevenLabs. If you'd like, I’m here to help you with any specific configurations or to dive deeper into details—just let me know!
Sources: agent/main.py | chain-of-thought-tts/agent.py | README.md | AI voice agents | LiveKit Docs | VoicePipelineAgent | LiveKit Docspolite-dog-12152
09/09/2025, 6:56 AMtall-airline-16756
09/09/2025, 6:57 AMimport logging
from dotenv import load_dotenv
from livekit.agents import llm
from livekit.agents.pipeline import VoicePipelineAgent
from livekit.plugins import deepgram, openai, silero
# Set logging for debugging
logging.basicConfig(level=logging.INFO)
# Load environment variables
load_dotenv(".env")
# Define system prompt
initial_ctx = llm.ChatContext().append(
role="system",
text="You are a helpful voice assistant. Respond concisely."
)
# Define a callback to filter text before TTS
async def before_tts_cb(agent: VoicePipelineAgent, text: str):
# Replace problematic words
return text.replace("error", "issue").replace("down", "unavailable")
# Initialize the VoicePipelineAgent with Groq as the LLM provider
agent = VoicePipelineAgent(
vad=silero.VAD.load(),
stt=deepgram.STT(model="nova-2-general"),
llm=openai.LLM.with_groq(model="llama3-70b-8192"), # example model
tts=openai.TTS(), # or any other TTS provider
before_tts_cb=before_tts_cb,
chat_ctx=initial_ctx,
allow_interruptions=True, # allow user to interrupt
)
# Start the agent
agent.start(room, participant)
This setup streams LLM responses in real time, using callbacks like before_tts_cb to customize text before it is synthesized into speech. Please feel free to reach out if you'd like help with specific configurations or if you'd like me to walk you through any part of this. I'm here to support you every step of the way!
Sources: chain-of-thought-tts/agent.py | livekit-plugins/livekit-plugins-google/livekit/plugins/google/llm.py | VoicePipelineAgent | LiveKit Docs | OpenAI compatible LLMs | LiveKit Docspolite-dog-12152
09/09/2025, 7:00 AMtall-airline-16756
09/09/2025, 7:00 AMLLM.chat() method gives you an LLMStream object, which you can iterate over asynchronously to handle response chunks bit by bit.
• Error Handling: The LLMStream class has strong error handling built in, turning provider-specific exceptions into standardized LiveKit exceptions so you get consistent behavior no matter which LLM provider you use.
• Customization: You have the flexibility to use callbacks like before_llm_cb to tweak the input context before it’s sent to the LLM, and before_tts_cb to adjust the output text before it’s turned into speech.
If you’d like, I’d be happy to share a specific example or dive deeper into how you can use LLMStream. Just let me know!polite-dog-12152
09/09/2025, 7:02 AMtall-airline-16756
09/09/2025, 7:02 AMpolite-dog-12152
09/09/2025, 7:02 AMpolite-dog-12152
09/09/2025, 7:16 AM