Whenever user end conversastion is there way to hu...
# ask-ai
s
Whenever user end conversastion is there way to hung up call in inbound call agent?
t
Thanks for reaching out, elish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To end a call when the user finishes the conversation, the inbound call agent can use the
delete_room
API. This action terminates the call for all participants. Here’s how it works: 1. Finish Ongoing Speech: Ensure any current speech output is completed before proceeding. 2. Call the
delete_room
API:
This API deletes the room, effectively ending the call. Here’s an example of how this can be implemented in code:
Copy code
async def hangup_call():
    ctx = get_job_context()
    if ctx is None:
        return
    await ctx.api.room.delete_room(
        api.DeleteRoomRequest(
            room=ctx.room.name,
        )
    )

class MyAgent(Agent):
    @function_tool
    async def end_call(self, ctx: RunContext):
        """Called when the user wants to end the call"""
        current_speech = ctx.session.current_speech
        if current_speech:
            await current_speech.wait_for_playout()
        await hangup_call()
This ensures the call is ended properly after the user leaves. Sources: Agents telephony integration | LiveKit Docs | Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs