Skip to main content

Overview

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.

How It Works

Idle detection monitors user activity and:
  1. Starts a timer when the bot finishes speaking (BotStoppedSpeakingFrame)
  2. Cancels the timer when the user or bot starts speaking
  3. Suppresses the timer during function calls, background work, and active user turns (to avoid false triggers during interruptions)
  4. Restarts the timer after a user turn that ends with no transcript and gets no reply (e.g. background noise)
  5. Emits an on_user_turn_idle event when the timer expires
  6. Allows you to implement escalating responses or gracefully end the conversation in your application code

Basic Implementation

Step 1: Enable Idle Detection

Enable idle detection by setting the user_idle_timeout parameter when creating your aggregator:

Step 2: Handle Idle Events

Create an event handler to respond when the user becomes idle:

Step 3: Implement Retry Logic (Optional)

For escalating responses, track retry count in your application:

Updating Timeout at Runtime

You can enable, disable, or change the idle timeout at runtime by pushing a UserIdleTimeoutUpdateFrame:
Immediate application: Timeout updates take effect immediately. If an idle timer is currently running, it restarts with the new duration. If the bot is waiting for the user to speak and you enable a positive timeout (e.g., upgrading from 0 to 10.0), the timer arms right away without waiting for the next bot turn. This is useful when you want to enable idle detection only at certain points in the conversation, or adjust the timeout based on context.

Detecting a Waiting User

Silence after the bot’s turn means one of two things, depending on whether the bot is still working in the background:
  • Idle: no background work is in progress. The user may have stepped away. user_idle_timeout and on_user_turn_idle cover this case.
  • Waiting: the bot is performing asynchronous background work, such as an asynchronous function call (cancel_on_interruption=False) or the work an LLMWithBackend backend has in flight. user_waiting_timeout and on_user_waiting cover this case.
The idle timeout doesn’t fire while background work is in progress. To check in with a user who is waiting, set user_waiting_timeout. The default, 0, turns it off:
Background work is bookended by BackgroundWorkStartedFrame and BackgroundWorkFinishedFrame, which share a work_id. LLMService and LLMWithBackend broadcast them for you. A component that dispatches other background work, such as a job to another worker, should broadcast the same pair so the user counts as waiting rather than idle. Both events are also broadcast as frames, UserTurnIdleFrame and UserWaitingFrame, each carrying quiet_secs (how long nothing has been said), so other processors can act on either silence. Change the waiting timeout at runtime with UserWaitingTimeoutUpdateFrame, the same way UserIdleTimeoutUpdateFrame changes the idle one:

Best Practices

  • Set appropriate timeouts: Shorter timeouts (5-10 seconds) work well for voice conversations
  • Use escalating responses: Start with gentle reminders and gradually become more direct
  • Limit retry attempts: After 2-3 unsuccessful attempts, consider ending the conversation gracefully by pushing an EndWorkerFrame
  • Reset on user activity: Use the on_user_turn_started event to reset your retry counter when the user speaks
  • Let the LLM respond naturally: Use developer messages to prompt the LLM rather than hardcoded TTS responses for more natural interactions

Next Steps

Try the User Idle Example

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.