numerous-whale-53652
07/06/2025, 3:56 PMtall-airline-16756
07/06/2025, 3:56 PMtall-airline-16756
07/06/2025, 3:57 PMuser_away_timeout
parameter. This allows you to detect when a user has been inactive and take appropriate actions. Here's a brief overview:
• Set the user_away_timeout
parameter when creating an AgentSession. For 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, # Set timeout to 12.5 seconds
)
• Handle the user_state_changed
event to respond when a user becomes inactive. For example: @session.on("user_state_changed")
def _user_state_changed(ev: UserStateChangedEvent):
if ev.new_state == "away":
# Handle user inactivity
inactivity_task = asyncio.create_task(user_presence_task())
else:
# User is active again, cancel inactivity task if it exists
if inactivity_task is not None:
inactivity_task.cancel()
• Define a task to handle user inactivity, such as prompting the user or closing the session. For example: async def user_presence_task():
# Try to ping the user multiple times
for _ in range(3):
await session.generate_reply(
instructions="The user has been inactive. Politely check if the user is still present."
)
await asyncio.sleep(10)
# If no response after attempts, close the session
await asyncio.shield(session.aclose())
ctx.delete_room()
The system automatically manages the user away timer, setting it when both the user and agent are in the "listening" state and canceling it when either party changes state.
Sources: GitHub::livekit::agents | livekit-plugins/livekit-plugins-gladia/livekit/pl...numerous-whale-53652
07/06/2025, 4:19 PMtall-airline-16756
07/06/2025, 4:19 PM