polite-furniture-24847
06/26/2025, 9:02 AMtall-airline-16756
06/26/2025, 9:02 AMtall-airline-16756
06/26/2025, 9:02 AMhangup_call()
function to delete the entire room, which will end the call for everyone. Here is an example:
async def hangup_call():
ctx = get_job_context()
if ctx is None:
# Not running in a job context
return
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
1. Remove a specific participant: Use the hangup()
method to remove a specific participant from the room. Here is an example:
async def hangup(self):
try:
await self.api.room.remove_participant(api.RoomParticipantIdentity(
room=self.room.name,
identity=self.participant.identity,
))
except Exception as e:
# it's possible that the user has already hung up, this error can be ignored
<http://logger.info|logger.info>(f"received error while ending call: {e}")
The first method ends the call for everyone, while the second method allows you to remove a specific participant. Let me know if you need further assistance!
Sources: Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docspolite-furniture-24847
06/26/2025, 9:03 AMtall-airline-16756
06/26/2025, 9:04 AM@function_tool
async def end_call(self, ctx: RunContext):
"""Called when the user wants to end the call"""
# let the agent finish speaking
current_speech = ctx.session.current_speech
if current_speech:
await current_speech.wait_for_playout()
await hangup_call()
And here's how you can handle the actual call hangup:
async def hangup_call():
ctx = get_job_context()
if ctx is None:
# Not running in a job context
return
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
This approach makes sure your agent gets to say goodbye properly before the call ends. Pretty neat, right? If you need any more help or have questions, I'm totally here for you!
Sources: Agents telephony integration | LiveKit Docspolite-furniture-24847
06/27/2025, 9:04 AMtall-airline-16756
06/27/2025, 9:04 AMhangup_call
function? I've got you covered! Let me break it down in a friendly way:
1. Manual Trigger: Think of this like having a big "end call" button. You can directly call the hangup_call
function from your agent. Here's a quick example that might help:
@function_tool
async def end_call(self, ctx: RunContext):
"""Called when the user wants to end the call"""
# let the agent finish speaking
current_speech = ctx.session.current_speech
if current_speech:
await current_speech.wait_for_playout()
await hangup_call()
1. Automated Trigger: Imagine your system being smart enough to know when it's time to say goodbye! This could mean hanging up after detecting a farewell message or meeting a specific condition.
2. API Integration: If you're more of a direct approach person, you can use the API to remove participants or delete the room - just like we discussed earlier.
Need more help figuring this out? I'm right here to help you navigate through it! Let me know what questions you have.
Sources: Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs