happy-fall-6105
09/03/2025, 12:18 PMtall-airline-16756
09/03/2025, 12:18 PMtall-airline-16756
09/03/2025, 12:18 PMtts_node to spot specific input patterns and make sure it doesn’t produce any output when those patterns show up.
Need a hand with the details? Just let me know—I’m here to help!
Sources: Pipeline nodes and hooks | LiveKit Docshappy-fall-6105
09/03/2025, 12:19 PMtall-airline-16756
09/03/2025, 12:20 PMStopResponse Exception: You can raise this exception in the on_user_turn_completed lifecycle hook to stop the response before it even starts. Here's a quick example:
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage) -> None:
if not new_message.text_content:
raise StopResponse() # This will stop the agent from replying
• Using session.interrupt() Method: This one stops any ongoing TTS playback and clears out queued responses. Check this out:
async def tts_node(self, text: AsyncIterable[str], model_settings: ModelSettings):
MAX_CHUNKS = 20
chunk_count = 0
async def process_text():
nonlocal chunk_count
interrupted = False
async for chunk in text:
chunk_count += 1
if chunk_count > MAX_CHUNKS and not interrupted:
self.session.interrupt()
self.session.say("I'm sorry, that will take too long to say.")
interrupted = True
break
if not interrupted:
yield chunk
return Agent.default.tts_node(self, process_text(), model_settings)
• Canceling User Input: Another option is to use session.clear_user_turn() or just disable audio input to make sure no responses get triggered.
If you want, I’m here to help you with any of these methods—just let me know!
Sources: livekit-agents/livekit/agents/voice/generation.py | pipeline-tts/short_replies_only.py | Pipeline nodes and hooks | LiveKit Docs