In conversational applications, it’s important to handle situations where users go silent or inactive. Pipecat provides built-in idle detection through LLMUserAggregator and UserTurnProcessor, allowing your bot to respond appropriately when users haven’t spoken for a defined period.
Create an event handler to respond when the user becomes idle:
@user_aggregator.event_handler("on_user_turn_idle")async def on_user_turn_idle(aggregator): # Send a reminder to the user message = { "role": "developer", "content": "The user has been quiet. Politely ask if they're still there.", } await aggregator.push_frame(LLMMessagesAppendFrame([message], run_llm=True))
For escalating responses, track retry count in your application:
class IdleHandler: def __init__(self): self._retry_count = 0 def reset(self): self._retry_count = 0 async def handle_idle(self, aggregator): self._retry_count += 1 if self._retry_count == 1: # First attempt - gentle reminder message = { "role": "developer", "content": "The user has been quiet. Politely ask if they're still there.", } await aggregator.push_frame(LLMMessagesAppendFrame([message], run_llm=True)) elif self._retry_count == 2: # Second attempt - more direct message = { "role": "developer", "content": "The user is still inactive. Ask if they'd like to continue.", } await aggregator.push_frame(LLMMessagesAppendFrame([message], run_llm=True)) else: # Third attempt - end conversation await aggregator.push_frame( TTSSpeakFrame("It seems like you're busy. Have a nice day!") ) await aggregator.push_frame(EndTaskFrame(), FrameDirection.UPSTREAM)# Use the handleridle_handler = IdleHandler()@user_aggregator.event_handler("on_user_turn_idle")async def on_user_turn_idle(aggregator): await idle_handler.handle_idle(aggregator)@user_aggregator.event_handler("on_user_turn_started")async def on_user_turn_started(aggregator, strategy): idle_handler.reset() # Reset retry count when user speaks
Explore a complete working example that demonstrates how to detect and
respond to user inactivity in Pipecat.
Turn Events
Learn about all available turn events and their parameters.
Implementing idle user detection improves the conversational experience by ensuring your bot can handle periods of user inactivity gracefully, either by prompting for re-engagement or politely ending the conversation when appropriate.