when interrupted during a conversation the voice a...
# ask-ai
w
when interrupted during a conversation the voice agent stops but continues from where it left off even though the customer has changed a context and asked something else....why?
t
Thanks for reaching out, Sunil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! So, the voice agent picks up right where it left off after an interruption because it’s built to keep the conversation flowing smoothly. When you jump in, it pauses to process what you said, but if it senses you’re still on the same topic, it might just continue instead of starting fresh. Here are a few ways you can handle this: • Try using callbacks like
before_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.py
w
give me example code to check if the context changed on user turn completed
t
Here’s a friendly example of how you can check for context changes in the
on_user_turn_completed
method:
Copy code
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!
w
does the voice agent send the information user provided to LLM to sense if the context has changed before it decides whether to continue on same topic or change?
t
Absolutely! The voice agent sends the information you provide along with the entire conversation history (using
ChatContext
) 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