big-school-62939
04/09/2026, 6:28 PMtall-airline-16756
04/09/2026, 6:28 PMtall-airline-16756
04/09/2026, 6:29 PMAgentSession object.
Sources: Job lifecycle | LiveKit Documentation | Build a salary negotiation coach with a LemonSlice avatar | LiveKit, with interactive elementsbig-school-62939
04/09/2026, 7:35 PMtall-airline-16756
04/09/2026, 7:35 PMfrom livekit.agents import JobContext
@server.rtc_session
async def my_agent(ctx: JobContext):
# Connect to the room (usually handled for you by the decorator)
await ctx.connect()
# ... agent logic, e.g. handle tracks, send/receive audio, etc. ...
# Graceful shutdown: request the agent session to end and disconnect the local participant.
# Use drain=True to allow any in-progress TTS/speech to finish playing.
ctx.shutdown(reason="Session complete", drain=True)
# If you need to wait until shutdown/cleanup completes, await aclose()
await ctx.aclose()
• Use ctx.shutdown(...) to request a graceful end (this disconnects the local participant).
• drain=True waits for any ongoing speech to finish before disconnecting.
• await ctx.aclose() performs an awaitable cleanup if you need to block until everything is fully closed., with interactive elements