red-television-3815
10/02/2025, 9:10 PMtall-airline-16756
10/02/2025, 9:10 PMtall-airline-16756
10/02/2025, 9:11 PMctx.shutdown() method to gently close the agent's connection while keeping other participants happily connected in the room. This method also takes care of triggering any shutdown hooks you've set up.
• End the session for all participants: If you want to wrap things up for everyone, you can use the delete_room API via the LiveKit server SDK. This deletes the entire room and disconnects all participants. You can do this using the LiveKitAPI client in Python or the RoomServiceClient in Node.js.
If you'd like, I’m here to guide you through detailed implementation steps or help with any specific programming language you’re working with. Just let me know!
Sources: Docs::Agents | telephony/sip_lifecycle.py | Inside a session | LiveKit Docs | Docs::Agents | agent.pyred-television-3815
10/02/2025, 9:11 PMtall-airline-16756
10/02/2025, 9:11 PMdelete_room API in Python. Here's a simple example you can follow:
from livekit import api
from livekit.agents import get_job_context
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,
)
)
In this example, the delete_room API is called to delete the room and gracefully disconnect everyone. Just make sure your environment variables LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET are set up correctly.
If you'd like, I’m here to provide more details or share examples in another programming language—just let me know!red-television-3815
10/02/2025, 9:13 PMtall-airline-16756
10/02/2025, 9:13 PMfrom livekit import api
from livekit.agents import get_job_context
from livekit.llm import function_tool
@function_tool
async def end_call(ctx):
"""Ends the session for all participants."""
ctx = get_job_context()
if ctx is None:
return "No active job context found."
try:
await ctx.api.room.delete_room(
api.DeleteRoomRequest(
room=ctx.room.name,
)
)
return "Session ended successfully."
except Exception as e:
return f"Error ending session: {e}"
Here’s a quick rundown:
• The @function_tool decorator helps register your function as a callable tool for the LLM.
• The function uses the delete_room API to end the session and thoughtfully returns a success or error message.
If you’d like, I’m here to help you with this setup or provide more examples—just let me know!