chilly-motorcycle-32290
08/01/2025, 12:06 PMtall-airline-16756
08/01/2025, 12:06 PMtall-airline-16756
08/01/2025, 12:07 PMLLMStream class. This class provides async iteration and handles real-time processing of LLM responses.
For example, you can use the chat() method of the LLM class to access an async iterable stream of ChatChunk objects. Here's a high-level example:
const llm = new openai.LLM(model="gpt-4");
const chatContext = new ChatContext();
// Add messages to the chat context...
const llmStream = llm.chat(chatContext);
// Use async iteration to process the stream
for await (const chunk of llmStream) {
console.log(chunk);
}
This functionality is supported across various LLM providers integrated with LiveKit, including OpenAI, Mistral, and Anthropic.
Let me know if you need further assistance or specific details about implementing this!
Sources: LLMStream | LiveKit Agents | LLMStream | LiveKit Agentschilly-motorcycle-32290
08/01/2025, 12:08 PMtall-airline-16756
08/01/2025, 12:08 PMAgentSession and connect it to a room:*`async def entrypoint(ctx: agents.JobContext):
session = AgentSession()
await session.start(
agent=MyAgent(),
room=ctx.room
)`
4. *Finally, run your agent with:*`if name == "__main__":
agents.cli.run_app(
WorkerOptions(entrypoint_fnc=entrypoint)
)`
Here’s what this setup does for you:
• STT: It turns audio into text using plugins like Deepgram or OpenAI.
• LLM: Processes that text and crafts a helpful response using OpenAI’s GPT.
• TTS: Converts the response back into audio with plugins like OpenAI or ElevenLabs.
If you have any questions or want me to walk you through any part in more detail, just let me know—I’m here to help!chilly-motorcycle-32290
08/01/2025, 12:12 PMtall-airline-16756
08/01/2025, 12:12 PMRoomOutputOptions and use LLMStream to get real-time text streaming going:
1. Turn Off Audio Output: Just set audio_enabled=False in your RoomOutputOptions to make sure no audio is sent out.
2. Turn Off Sync Transcription: Set sync_transcription=False so transcriptions come through as soon as they’re ready, without waiting to sync with any audio.
3. Stream the Text: Your agent will send text responses to the lk.transcription topic. On the frontend, you can catch these messages using registerTextStreamHandler for the lk.transcription topic and then display the text however you like.
Here’s a quick example configuration to get you started:
session = AgentSession(
llm=openai.LLM(model="gpt-4o-mini"),
)
await session.start(
agent=MyAgent(),
room=ctx.room,
room_input_options=RoomInputOptions(text_enabled=True, audio_enabled=False),
room_output_options=RoomOutputOptions(
transcription_enabled=True,
audio_enabled=False,
sync_transcription=False
),
)
And on the frontend, you can handle the stream like this:
room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => {
const message = await reader.readAll();
console.log(`New message from ${participantInfo.identity}: ${message}`);
});
This way, you’ll have text streaming smoothly to your UI without any audio or sync delays. If you have any questions or want to tweak this further, just let me know — I’m here to help!
Sources: LLM | LiveKit Agents | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs