chilly-balloon-11273
09/17/2025, 9:30 AMtall-airline-16756
09/17/2025, 9:30 AMtall-airline-16756
09/17/2025, 9:30 AMuser_away_timeout parameter in the AgentSession configuration. This handy feature changes the user’s state to "away" after a set period of inactivity, which you can then use to gently prompt the user or disconnect them if needed.
Method 1: Using user_away_timeout in AgentSession (Recommended)
Simply set user_away_timeout=10.0 when you create your AgentSession. Then, listen for the user_state_changed event to know when the user becomes "away" and respond accordingly.
from livekit.agents import AgentSession, UserStateChangedEvent
session = AgentSession(
vad=silero.VAD.load(),
llm=openai.LLM(),
stt=deepgram.STT(),
tts=cartesia.TTS(),
user_away_timeout=10.0, # Timeout after 10 seconds of inactivity
)
@session.on("user_state_changed")
async def on_user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "away":
# Prompt the user or end the session
await session.generate_reply(
instructions="Are you still there? Let me know if you need help."
)
# Optionally close the session after a few attempts
Method 2: Using the InactivityHandler Extension
LiveKit also offers a reusable InactivityHandler in the agent-demos repository. This extension automatically monitors for silence and sends a message after the timeout period, making things even easier for you.
from agent_extensions.handlers import InactivityHandler
inactivity_handler = InactivityHandler(
timeout_seconds=10,
inactivity_message="Are you still there? Let me know if you need any help."
)
inactivity_handler.start(agent)
Both of these options give you the flexibility to customize how long the timeout lasts and what message to send. If you have any questions or need a hand setting this up, just let me know—I’m here to help!
Sources: Events and error handling | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | agent_extensions/README.md | Events and error handling | LiveKit Docs