a
.
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you out! Could you please share a bit more about what you're experiencing or what you need? That way, I can make sure to assist you in the best possible way.
a
How to delete or stop a session as I can see my session is still on where I already ended up the call
t
I'm here to help you gracefully stop or delete a session after ending a call. Here are some simple steps you can follow: • End the session for all participants: You can use the
deleteRoom
API to close the entire LiveKit room session. This will disconnect everyone and make sure any recordings stop smoothly. This is the best way to fully clean up the session. • Disconnect only the agent: If you'd like to keep the session active for others, you can just disconnect the agent while letting the rest continue. • Stop active egress (if applicable): If your session includes recording or streaming, you can manually stop these using the
StopEgress
API. But don’t worry—deleting the room will take care of this automatically too. For the smoothest experience, I recommend using the
deleteRoom
API to make sure everything wraps up nicely and all resources are freed. If you’d like, I’m here to guide you through these steps or answer any questions you have! Sources: Job lifecycle | LiveKit Docs | Egress examples | LiveKit docs | Agents telephony integration | LiveKit Docs | Connecting to LiveKit | LiveKit docs | Managing rooms | LiveKit docs
a
see in my agent file attached i want to introduce the delete room called when it ends even if agent was not able to call the end call function.. add this room delete in the add s shutdown call or wherever itsthere
t
I completely understand wanting to make sure the room gets deleted even if the agent doesn’t explicitly call the end function. To help with that, you can integrate the room deletion logic right into the shutdown process. Here are a few approaches I recommend: • Automatic Room Deletion: You can use the
delete_room_on_close=True
option within
RoomInputOptions
. This will take care of deleting the room automatically when the agent session ends. Here’s a quick example:
Copy code
from livekit.agents.voice import RoomInputOptions

await session.start(
    agent=MyAgent(),
    room=ctx.room,
    room_input_options=RoomInputOptions(delete_room_on_close=True),
)
• Manual Room Deletion in Shutdown Callback: Another way is to add a shutdown callback that deletes the room manually. Here’s how you can do it:
Copy code
from livekit import api

@ctx.on("shutdown")
async def on_shutdown(reason: str):
    await ctx.api.room.delete_room(api.DeleteRoomRequest(room=ctx.room.name))
• Using JobContext's Built-in Method: You can also use the handy
ctx.delete_room()
method, which includes built-in error handling. For example:
Copy code
@ctx.on("shutdown")
async def on_shutdown(reason: str):
    await ctx.delete_room()
In most situations, I’d suggest going with the automatic deletion option (
delete_room_on_close=True
) since it makes things simpler and helps ensure the room is cleaned up reliably. If you’d like, I’m here to walk you through implementing this or answer any questions you might have! Sources: livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py | telephony/sip_lifecycle.py | Managing rooms | LiveKit docs
a
class RoomInputOptions: text_enabled: NotGivenOr[bool] = NOT_GIVEN """If not given, default to True.""" audio_enabled: NotGivenOr[bool] = NOT_GIVEN """If not given, default to True.""" video_enabled: NotGivenOr[bool] = NOT_GIVEN """If not given, default to False.""" audio_sample_rate: int = 24000 audio_num_channels: int = 1 noise_cancellation: rtc.NoiseCancellationOptions | None = None text_input_cb: TextInputCallback = _default_text_input_cb participant_kinds: NotGivenOr[list[rtc.ParticipantKind.ValueType]] = NOT_GIVEN """Participant kinds accepted for auto subscription. If not provided, accept
DEFAULT_PARTICIPANT_KINDS
.""" participant_identity: NotGivenOr[str] = NOT_GIVEN """The participant to link to. If not provided, link to the first participant. Can be overridden by the
participant
argument of RoomIO constructor or
set_participant
.""" pre_connect_audio: bool = True """Pre-connect audio enabled or not.""" pre_connect_audio_timeout: float = 3.0 """The pre-connect audio will be ignored if it doesn't arrive within this time.""" close_on_disconnect: bool = True """Close the AgentSession if the linked participant disconnects with reasons in CLIENT_INITIATED, ROOM_DELETED, or USER_REJECTED.""" i have this options to choose in input.. which to choose
t
I’m happy to help you ensure the room gets deleted when the agent session ends! You can achieve this by using the
delete_room_on_close
option in
RoomInputOptions
. Just set this option to
True
when you start the agent session. Here’s a simple example to guide you:
Copy code
from livekit.agents import RoomInputOptions

# Configure RoomInputOptions to delete room on session close
room_input_options = RoomInputOptions(
    delete_room_on_close=True,
)

# Start the agent session with the configured options
await session.start(
    agent=MyAgent(),
    room=ctx.room,
    room_input_options=room_input_options,
)
This will take care of deleting the room automatically once the session ends, helping keep everything neat and tidy. If you have any more questions or need a hand with anything else, please don’t hesitate to ask—I’m here to support you! Sources: examples/voice_agents/multi_agent.py | Development Tools & Resources | livekit/livekit_composite | DeepWiki | agents/src/voice/room_io/room_io.ts