aloof-scooter-47164
09/07/2025, 12:12 AMtall-airline-16756
09/07/2025, 12:12 AMtall-airline-16756
09/07/2025, 12:12 AMuser_state_changed event along with the user_away_timeout parameter in AgentSession. Just a heads-up, this isn’t something you can control through the external LiveKit API.
Here’s a friendly step-by-step on how to get this working:
• Set the user_away_timeout parameter in AgentSession to decide how long the user should be inactive before being marked as away.
• Add a listener for the user_state_changed event so you know exactly when the user is marked away.
• Inside that event handler, call session.generate_reply() or session.say() to have your agent speak up.
Here’s a quick example to illustrate:
@session.on("user_state_changed")
def on_user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "away":
asyncio.create_task(session.generate_reply(
instructions="The user has been inactive. Politely check if they're still there."
))
Or, if you’d prefer something simpler, you can try out the InactivityHandler from the agent_extensions package.
For a full working example, feel free to check out the inactive_user.py example. It’s a great resource to get you started!
Sources: Events and error handling | LiveKit Docs | examples/avatar_agents/audio_wave/agent_worker.py | agent_extensions/README.md | Dispatching agents | LiveKit Docsaloof-scooter-47164
09/07/2025, 12:18 AMtall-airline-16756
09/07/2025, 12:18 AMuser_state_changed event we talked about earlier.
If you'd like a hand with setting this up or have any other questions, just let me know—I'm here to help!