acoustic-guitar-10279
07/21/2025, 12:39 PMtall-airline-16756
07/21/2025, 12:39 PMtall-airline-16756
07/21/2025, 12:40 PMon_user_turn_complete is triggered by implementing the on_user_turn_completed lifecycle hook in your Agent class.
Here's how to use it:
from livekit.agents import Agent, ChatContext, ChatMessage
class MyAgent(Agent):
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage) -> None:
# Your custom logic here
await self.my_custom_function(new_message.content)
• on_user_turn_completed is called automatically when the user's turn ends, before the agent's reply.
• You can run any function or logic inside this method.
• The method receives the chat context and the user's latest message as parameters.
This hook is ideal for preprocessing user input, adding context, or triggering side effects before the agent responds. For realtime models, ensure turn detection is handled in your agent to use this hook.
Sources: Voice pipeline nodes | LiveKit Docs | External data and RAG | LiveKit Docs | complex-agents/shopify-voice-shopper/shopify.pyacoustic-guitar-10279
07/21/2025, 12:40 PMtall-airline-16756
07/21/2025, 12:42 PMacoustic-guitar-10279
07/26/2025, 3:48 PM