i have end call tool function so the agent will en...
# ask-ai
p
i have end call tool function so the agent will end the call when the conversation is finished with the user, but there is issue with it the room is never deleted and call keep going class myAgent(Agent): def __init__(self, chat_ctx: ChatContext, instructions: str): super().__init__(chat_ctx=chat_ctx, instructions=instructions) async def hangup(self): """Hang up by deleting the room (disconnects everyone).""" job_ctx = get_job_context() if job_ctx is None: logger.warning("[hangup] No JobContext available (not in a job?)") return try: await job_ctx.delete_room() logger.info("[hangup] Room deleted") except Exception as e: # It's fine if room is already gone logger.info(f"[hangup] received error while ending call: {e}") @function_tool() async def end_call(self, ctx: RunContext): """Called when the user wants to end the call.""" # Let TTS finish before tearing down try: current_speech = getattr(ctx.session, "current_speech", None) if current_speech: await current_speech.wait_for_playout() except Exception: pass await asyncio.sleep(1) # small grace so audio flushes await self.hangup()
t
Thanks for reaching out, Yasser. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The issue with the room not being deleted when using the
delete_room
function can happen for a few reasons. Let’s walk through some easy steps to help you figure it out and get things working: • Verify Room Existence: Try using the
list_rooms
function first to make sure the room is actually there before you try deleting it. • Check Permissions: Double-check that the API key you’re using has the
roomCreate
permission—this is needed to delete a room. • Correct Room Name: Make sure the room name or ID you’re passing to the
delete_room
function is exactly right. • Handle Errors: Keep an eye on any error messages from the
delete_room
function—they can give you clues about what’s going wrong. • Active Participants: Just a heads-up: if there are active participants in the room, they’ll get disconnected once the room is deleted successfully. If you’re still stuck after trying these, feel free to share more details like the exact error messages, the room name you’re using, and any logs you have. I’m here to help you get this sorted out! Sources: livekit/livekit_room.twirp.go
p
here how i used to do it in the old sdk and it was working, async def hangup(self): try: await self.api.room.delete_room(api.DeleteRoomRequest(room=self.room.name)) except Exception as e: # it's possible that the user has already hung up, this error can be ignored logger.info(f"received error while ending call: {e}") @llm.ai_callable() async def end_call(self): """Called when the user wants to end the call""" logger.info(f"ending the call for {self.participant.identity}") await self.hangup()
t
The behavior of the
delete_room
function in the new SDK might feel a bit different compared to the old SDK, especially when it comes to non-RTC rooms (those rooms created but without any participants joined). In the new SDK, these rooms are explicitly loaded and deleted from the room store. For rooms that do have participants, things should work pretty much the same—the room gets closed, and everyone’s disconnected. If your code worked fine with the old SDK but is acting up with the new one, here are a few friendly tips to check: • Make sure the room actually exists by using
list_rooms
before you try deleting it. • Double-check that you’re passing the right room name to the
delete_room
function. • Keep an eye out for any error messages from the
delete_room
call—they can give you helpful clues. If you’re still stuck, feel free to share more about the room’s status (like if it has participants or if it’s a non-RTC room) and any errors you’re seeing. I’m here to help you figure it out! Sources: pkg/service/roomservice_test.go