thankful-plastic-70087
09/19/2025, 9:54 AMtall-airline-16756
09/19/2025, 9:54 AMtall-airline-16756
09/19/2025, 9:55 AMthankful-plastic-70087
09/19/2025, 9:55 AMtall-airline-16756
09/19/2025, 9:56 AMthankful-plastic-70087
09/19/2025, 9:59 AMtall-airline-16756
09/19/2025, 10:00 AMon_user_turn_completed lifecycle hook. This lets you fetch and add relevant context right before the LLM generates its response. Here's a simple example to guide you:
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage) -> None:
# Perform RAG lookup using the user's message
rag_content = await my_rag_lookup(new_message.text_content())
# Add retrieved content to chat context
turn_ctx.add_message(
role="assistant",
content=f"Additional information relevant to the user's next message: {rag_content}"
)
# Persist context changes
await self.update_chat_ctx(turn_ctx)
This method helps ensure that the extra context is smoothly included in the conversation right before the agent replies, making interactions more meaningful.
If you're coming from an older LiveKit version, you might also consider using the llm_node method. Just let me know if you'd like me to walk you through that or if you need any assistance setting up your RAG system—I’m here to help!
Sources: agents/src/voice/room_io/room_io.ts | Pipeline nodes and hooks | LiveKit Docs | rag/rag_handler.py | delay-handling/agent.py | livekit-agents/livekit/agents/voice/room_io/room_io.pythankful-plastic-70087
09/19/2025, 10:03 AMtall-airline-16756
09/19/2025, 10:03 AMlk.chat topic with LiveKit's text stream API. Here's a simple way to handle this:
Sending Chat Messages:
const text = 'Hello, how are you today?';
const info = await room.localParticipant.sendText(text, {
topic: 'lk.chat',
});
Receiving Chat Messages:
room.registerTextStreamHandler('lk.chat', async (reader, participantInfo) => {
const message = await reader.readAll();
console.log(`New message from ${participantInfo.identity}: ${message}`);
});
If you're using LiveKit Agents, they’ll automatically keep an eye on the lk.chat topic for any incoming messages and can handle them smoothly. Please feel free to reach out if you'd like assistance integrating this with your RAG setup or if you want to customize the behavior even more—I’m here to help!
Sources: Agents v0.x migration guide - Node.js | LiveKit Docs | packages/react/src/hooks/useDataChannel.ts | Text and transcriptions | LiveKit Docs | Text and transcriptions | LiveKit Docs