mysterious-agent-76276
12/17/2025, 3:27 AMtall-airline-16756
12/17/2025, 3:27 AMtall-airline-16756
12/17/2025, 3:27 AMuser_started_speaking event and update a timestamp).
• Run a background task that periodically checks the timestamp.
• If silence exceeds 30 seconds, call await ctx.room.disconnect() to hang up.
Minimal pattern (Python)
import asyncio, time
SILENCE_THRESHOLD = 30
async def entrypoint(ctx: JobContext):
last_spoke = time.time()
@agent.on("user_started_speaking")
def on_user_started_speaking(_msg):
nonlocal last_spoke
last_spoke = time.time()
async def monitor():
while True:
if time.time() - last_spoke > SILENCE_THRESHOLD:
await ctx.room.disconnect()
break
await asyncio.sleep(1)
monitor_task = asyncio.create_task(monitor())
session = AgentSession(...)
await session.start(room=ctx.room, agent=agent)
@ctx.on("shutdown")
def on_shutdown():
monitor_task.cancel()
Notes
• AgentSession(user_away_timeout=...) changes when UserState.away is set (default 15s) but does not automatically disconnect; you still need the custom hangup logic.
• This same pattern is used for voicemail/silence detection use cases.
Would you like the snippet adapted to your existing agent code or to a different language?
Sources: How to detect and handle silence during calls | examples/frontdesk | livekit/livekit_composite | DeepWiki | Events and error handling | LiveKit docs