I want to have user_away_timeout set. If the user ...
# ask-ai
q
I want to have user_away_timeout set. If the user has not spoken for certain number of seconds then we want to ask user if they are still there or not
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can help you set up a user_away_timeout so the system detects silence and prompts the user to confirm they’re still there. Below is a concise approach you can follow. I’m responding to your request to mark users as “away” after N seconds of silence and then prompt them. 1) Configure the timeout on the AgentSession • Set
user_away_timeout
to the number of seconds of silence before the user is considered away. Example:
Copy code
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:
Copy code
@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:
Copy code
# 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 | LiveKit
q
If the user has put the agent on hold, and there is a hold music going on, would this change the user state to away
t
Thanks — I’m answering your question about whether hold music will change the user state to “away.” Short answer: No — hold music does not count as user audio input, so playing hold music to the user does not itself prevent the user from becoming "away." Details: • The user state is determined by detection of the user’s audio (voice activity). If no user audio is detected for longer than the configured
user_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