crooked-dawn-90821
09/23/2025, 4:46 PMtall-airline-16756
09/23/2025, 4:46 PMtall-airline-16756
09/23/2025, 4:46 PMturn_detection="manual" in the AgentSession configuration. This way, automatic turn detection is turned off, and you get to decide exactly when the agent listens and processes user input.
Here’s a simple way to do it:
• Use session.clearUserTurn() to clear any previous user input and reset the turn state, so the agent patiently waits for new input.
• When you’re ready for the agent to respond, call session.commitUserTurn() to process the current user input.
• If needed, you can also use session.interrupt() to stop the agent from speaking before waiting for the user.
For example, you might create an RPC method like start_turn that your frontend can call to tell the agent to wait for the user:
ctx.room.localParticipant?.registerRpcMethod('start_turn', async () => {
session.interrupt(); // Stop agent from speaking
session.clearUserTurn(); // Reset user input state
return 'ok';
});
This method gently instructs the agent to "skip" its current turn and wait as long as needed until commitUserTurn() is triggered.
If you'd like to see this in action, there’s a complete example in the Push-to-Talk Agent. Feel free to explore it, and don’t hesitate to reach out if you have any questions along the way!
Sources: Turn detection and interruptions | LiveKit Docs | examples/src/push_to_talk.ts