I have *`on_user_turn_completed`* in my agent defi...
# ask-ai
r
I have
on_user_turn_completed
in my agent definition, but it is not being called after text chat messages, how to do that?
t
Thanks for reaching out, Ivan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're correct—I'll explain. Regarding your
on_user_turn_completed
hook: it only fires after audio input ends (VAD/STT/turn-detection). Text messages sent via chat do not trigger that hook. To handle text chat messages, use the text input callback (
text_input_cb
/
textInputCallback
) in your RoomInputOptions / inputOptions. Example patterns: Python:
Copy code
def custom_text_input_handler(session: AgentSession, event: TextInputEvent) -> None:
    message = event.text
    session.interrupt()
    session.generate_reply(user_input=message)

session = AgentSession(
    # ...
    room_input_options=RoomInputOptions(
        text_input_cb=custom_text_input_handler
    )
)
Node.js:
Copy code
const customTextInputHandler = (session: voice.AgentSession, event: voice.TextInputEvent): void => {
  const message = event.text;
  session.interrupt();
  session.generateReply({ userInput: message });
};

await session.start({
  // ...
  inputOptions: {
    textInputCallback: customTextInputHandler,
  },
});
Would you like help converting your current handler to use
text_input_cb
, or to share the relevant code so I can suggest the exact changes? Sources: Pipeline nodes and hooks | LiveKit docs | Turn detection and interruptions | LiveKit Docs | Text and transcriptions | LiveKit docs