witty-kangaroo-6889
09/05/2025, 2:08 AMtall-airline-16756
09/05/2025, 2:08 AMtall-airline-16756
09/05/2025, 2:08 AMbefore_llm_cb to tweak the conversation context and spot when the topic changes.
• Play around with interruption sensitivity settings—like setting a minimum word count before it counts as an interruption.
• Add your own logic in on_user_turn_completed to check the user’s input and decide if the conversation should keep going or reset.
• If you want to be extra sure, you can turn off resuming altogether for important parts by setting resume_false_interruption=False.
Need a hand with setting up any of these? I’m here to help!
Sources: Building the all-in-one platform for voice AI agents | Building the all-in-one platform for voice AI agents | VoicePipelineAgent | LiveKit Docs | tests/test_agent_session.pywitty-kangaroo-6889
09/05/2025, 2:11 AMtall-airline-16756
09/05/2025, 2:11 AMon_user_turn_completed method:
from livekit import ChatContext, ChatMessage
class CustomVoiceAgent(VoicePipelineAgent):
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
# Grab the latest user input
user_input = new_message.text_content.lower()
# List some keywords or phrases that might mean the user wants to change the topic
context_change_keywords = ["new topic", "change subject", "let's talk about"]
# See if the user said anything that matches those keywords
if any(keyword in user_input for keyword in context_change_keywords):
# We’ve spotted a context change!
print("Context change detected. Resetting conversation state.")
# You can reset the conversation or create a fresh response here
self.session.generate_reply(user_input="User wants to switch topics.")
else:
# No change detected, so we keep going as usual
print("No context change detected. Proceeding with the current flow.")
Here’s what’s happening:
• The method looks at the latest user input to spot any keywords or phrases that suggest a context change.
• If it finds one, you can reset the conversation or generate a new reply to keep things smooth.
• If not, the agent just keeps rolling with the current conversation.
Feel free to tweak the context_change_keywords list or even add more advanced stuff like intent classification to make it fit your needs perfectly. And hey, if you want me to help out more, just let me know!witty-kangaroo-6889
09/05/2025, 2:14 AMtall-airline-16756
09/05/2025, 2:14 AMChatContext) to the LLM. This helps the LLM understand any changes in context and decide whether to keep the conversation going on the same topic or switch things up.
Here’s how it works:
• It keeps track of the whole conversation using ChatContext, which stores all the messages.
• It uses handy callbacks like on_user_turn_completed or before_llm_cb to tweak or add to the context before sending it off to the LLM.
• The LLM then reads this updated context and figures out the best response based on its training and the system prompt.
If you'd like, I’m happy to dive deeper into how you can customize this or set up specific ways to handle context. Just let me know!
Sources: VoicePipelineAgent | LiveKit Docs | livekit-agents/livekit/agents/voice/agent.py | External data and RAG | LiveKit Docs | Model Context Protocol Integration | livekit/livekit_composite | DeepWiki