quick-cartoon-22764
03/09/2026, 3:52 PMtall-airline-16756
03/09/2026, 3:52 PMtall-airline-16756
03/09/2026, 3:53 PMuser_away_timeout to the number of seconds of silence before the user is considered away. Example:
session = AgentSession(
vad=silero.VAD.load(),
llm=openai.LLM(model="gpt-4o-mini"),
stt=deepgram.STT(),
tts=cartesia.TTS(),
user_away_timeout=12.5, # seconds of silence before user is marked "away"
)
2) Listen for the user_state_changed event and prompt when the user becomes away
• When you receive user_state_changed with new_state == "away", generate a polite prompt asking if they’re still present:
@session.on("user_state_changed")
async def _user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "away":
# ask the user if they're still there
await session.generate_reply(
instructions="The user has been silent for a bit. Politely ask if they are still there."
)
3) Cancel the inactivity prompt if the user speaks again
• If state changes from away back to speaking, cancel any pending inactivity prompt or task so you don’t interrupt the resumed conversation:
# track the pending task somewhere accessible
if ev.new_state == "away":
inactivity_task = asyncio.create_task(user_presence_task())
return
# user came back
if inactivity_task is not None:
inactivity_task.cancel()
inactivity_task = None
Notes and suggestions
• Choose a timeout value that fits your UX (e.g., 10–15s for short prompts, longer for slower interactions).
• The prompt content can be simple and friendly: “Are you still there?” or include an offer to reconnect/help if needed.
• If you need different behavior (e.g., send a visual UI notification instead of voice, retry prompts, or escalate after repeated no-responses), tell me which option you prefer and I’ll outline the code changes.
If you want, share:
• the timeout value you prefer, and
• whether you want voice, visual, or both types of prompts
I’ll provide a tailored snippet for that setup.
Sources: How to detect and handle silence during calls | LiveKitquick-cartoon-22764
03/09/2026, 4:18 PMtall-airline-16756
03/09/2026, 4:18 PMuser_away_timeout, the state transitions to "away".
• Hold music is output audio (played to the user) and is not treated as user input, so it won’t reset the silence timer.
• That means if the user is on hold and not speaking, and silence from the user exceeds user_away_timeout (for example, 10–15 seconds), you will still receive a user_state_changed event with new_state = "away".
If you want to treat "on hold" differently (for example, avoid marking the user away while music is playing), two options:
• Use a frontend or signaling flag to tell the agent the call is on hold, and suppress away-handling while that flag is set.
• Extend your logic to ignore user_state_changed -> away events when your application knows hold music is active.
If you’d like, tell me:
• the user_away_timeout value you’re using, and
• whether you can send a hold flag from your client;
I’ll give a small code snippet showing how to ignore away transitions while hold is active.
Sources: How to implement call greeting retries in voice agents | LiveKit | Job lifecycle | LiveKit Documentation