how to run a function tool everytime on_user_turn_...
# ask-ai
a
how to run a function tool everytime on_user_turn_complete
t
Thanks for reaching out, Harshita. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can automatically run a function every time
on_user_turn_complete
is triggered by implementing the
on_user_turn_completed
lifecycle hook in your Agent class. Here's how to use it:
Copy code
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.py
a
not a function but function_tool
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
a
getting this error Error in _bounce_eou_task