I am depending upon the handleDisconnected function
<LiveKitRoom
serverUrl={liveKitUrl}
token={token}
connect={true}
audio={{ deviceId: selectedDevice }}
video={false}
onConnected={handleConnected}
onDisconnected={handleDisconnected}
onError={handleError}
onMediaDeviceFailure={handleMediaDeviceFailure}
>
I have changed my code, and now I am using
delete_room_on_close = True
When the interview ends via the tool function in Python, the room is deleted and my handleDisconnected function runs correctly.
However, when I set delete_room_on_close=False, the agent disconnects at the end of the interview but handleDisconnected is not being called on the frontend.
Could you confirm whether my current approach is correct and production ready? And if delete_room_on_close=False it is needed, what is the recommended way to ensure the frontend receives a disconnection event when I call session.shutdown()
`async def end_interview():
logger.info("\n 🛑 TOOL CALLED: end_interview")
ctx.agent.end_reason = "assistant-said-end-call-phrase"
await session.say("Thank you for your time. Goodbye!", allow_interruptions=False)
session.shutdown(drain=True)`
`await session.start(
room=ctx.room,
agent=InterviewAgent(instructions=instructions, ctx=ctx),
room_options=room_io.RoomOptions(
audio_input=room_io.AudioInputOptions(
noise_cancellation=noise_cancellation.BVC(),
),
#forcefully close room and monitor sync API Call
delete_room_on_close=True,
),
# record=True, // it is recording file in server
)`
`@session.on("close")
def on_closed(session):
logger.info("\n ------ Cleaning up timeout task on session close ------")
logger.info(f"Session closed Usage: {usage.get_summary()}")
try:
json_data = get_session_report_json(ctx)
if environment != "local":
logger.info( f" Close event: {json.dumps(json_data, default=str)}")
# 🚀 Fire the webhook immediately when the session closes
# Create a background task so it doesn't block the event loop
asyncio.create_task(send_session_report(ctx))
except Exception as e:
logger.error(f"Error getting session report: {e}")
timeout_task.cancel()`
I want to confirm the following three things:
1. Correct use case of delete_room_on_close Which option is recommended for an interview session — True or False? What is the intended use case for each?
2. Guaranteed @session.on("close") callback after session.shutdown() When I call session.shutdown(), I need to guarantee that the following callback is always triggered:
@session.on(“close”)
def on_closed(session):
I am using this callback to send the chat history to my backend API. Could you confirm this is reliable? Or is there a better approach such as a webhook to ensure the chat history and session report are always delivered to my backend without any missed calls?
3. Frontend onDisconnected callback after session.shutdown() When session.shutdown() is called from the agent, I need the frontend LiveKit SDK to reliably trigger the onDisconnected callback from <LiveKitRoom/>.
Could you confirm this is the expected behaviour and suggest the correct way to ensure it always fires?
The
current setup of the agent session has
delete_room_on_close=True,