How to properly handle the sip session after delet...
# ask-ai
b
How to properly handle the sip session after deleting a room. Currently using this in a function_tool:
Copy code
await ctx.room.disconnect()  
 await ctx.delete_room()
or
Copy code
ctx = get_job_context()
await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
deletes the room and detach the agent correctly but the sip session keeps active (no bye received by caller nor sent by livekit)
t
Thanks for reaching out, Jesus. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's make sure your SIP sessions are properly handled after deleting a room in LiveKit. Here are some helpful steps to guide you through the process: • Start by using the
deleteRoom
API to end the room along with all participants, including SIP sessions. Here's a quick example for you:
Copy code
await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
• Consider enabling the
delete_room_on_close
option in agents to automatically clean up the room once the session ends. This can save you some effort! • Keep an eye on the SIP call status using participant attributes like
sip.callStatus
. When you see it change to "hangup," that’s a great time to trigger the room deletion. • If you're deleting rooms from the frontend, make sure to use secure API routes to call the
deleteRoom
API safely. Following these steps will help you close SIP sessions smoothly, preventing any lingering active calls or silent participants. If you have any questions or need further help, I’m here for you! Sources: livekit-agents/livekit/agents/voice/room_io/room_io.py | Job lifecycle | LiveKit Docs | Connecting to LiveKit | LiveKit Docs | Agents telephony integration | LiveKit Docs | Inside a session | LiveKit Docs