hundreds-lamp-38428
10/13/2025, 2:36 PMtall-airline-16756
10/13/2025, 2:36 PMtall-airline-16756
10/13/2025, 2:37 PMctx.shutdown() without disconnecting other SIP participants, here’s a gentle approach you can follow: 1. Use await session.aclose() to gracefully close the AI agent's session. 2. Try to avoid calling delete_room, as this will disconnect everyone, including SIP callers. Here’s a friendly example to guide you:
async def entrypoint(ctx: agents.JobContext):
session: AgentSession | None = None
try:
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
shutdown_future = asyncio.Future()
def _on_shutdown(reason: str):
if not shutdown_future.done():
shutdown_future.set_result(None)
ctx.add_shutdown_callback(_on_shutdown)
participant = await ctx.wait_for_participant(
kind=rtc.ParticipantKind.PARTICIPANT_KIND_STANDARD
)
session = AgentSession(
# Configure LLM, STT, TTS, etc.
)
await session.start(room=ctx.room, agent=MyAgent())
done, _ = await asyncio.wait(
[shutdown_future],
return_when=asyncio.FIRST_COMPLETED,
)
finally:
if session:
await session.aclose() # This disconnects only the AI agent
This way, the AI agent can leave the call smoothly while your SIP participants stay connected. If you have any questions or need a hand with anything else, I’m here to help! Sources: Agent-assisted warm transfer | LiveKit Docs | Agents telephony integration | LiveKit Docs | Job lifecycle | LiveKit Docs | SIP overview | LiveKit Docshundreds-lamp-38428
10/13/2025, 2:40 PMtall-airline-16756
10/13/2025, 2:40 PMawait session.aclose() is disconnecting all participants, it might be due to a configuration setting that needs a little adjustment. Let’s walk through some important points to check together: 1. Make sure delete_room_on_close=False: When this option is set to True in RoomInputOptions, the whole room gets deleted as soon as the agent session closes. Double-check your setup like this: python room_input_options=RoomInputOptions(delete_room_on_close=False) 2. Look out for custom shutdown hooks: Sometimes, if your code has event listeners (such as participant_disconnected) that call ctx.delete_room() without distinguishing between agent and non-agent participants, it might unintentionally delete the room when the agent leaves. It’s a good idea to ensure these listeners are properly filtering participants. 3. Consider setting close_on_disconnect=False if it fits your use case: This helps prevent the agent session from closing automatically when the linked participant disconnects. Just keep in mind, it won’t affect manual calls to aclose(). Take a moment to review these settings, and if you’re still running into trouble, please don’t hesitate to reach out. I’m here to help you get this sorted! Sources: Job lifecycle | LiveKit Docs | livekit-plugins/livekit-plugins-deepgram/livekit/plugins/deepgram/tts.py | Agents telephony integration | LiveKit Docshundreds-lamp-38428
10/13/2025, 2:43 PMtall-airline-16756
10/13/2025, 2:44 PMRoomInputOptions.close_on_disconnect=False in Python, you can easily configure it when starting an AgentSession. Here’s a simple example to guide you:
from livekit.agents import AgentSession, RoomInputOptions
# Start the agent session with close_on_disconnect disabled
session = AgentSession()
await session.start(
room=ctx.room,
agent=MyAgent(),
room_input_options=RoomInputOptions(close_on_disconnect=False),
)
This way, your agent session will stay active even if the linked participant disconnects. If you have any questions or need a hand with anything else, just let me know—I’m here to help! Sources: Development Tools | livekit/livekit_composite | DeepWiki | examples/voice_agents/session_close_callback.pyhundreds-lamp-38428
10/13/2025, 4:03 PMtall-airline-16756
10/13/2025, 4:04 PMdelete_room_on_close option is turned on. To keep the room open, you can set up your RoomInputOptions like this:
await session.start(
agent=MyAgent(),
room=ctx.room,
room_input_options=RoomInputOptions(
delete_room_on_close=False # Prevents automatic room deletion
),
)
By doing this, your room will stay active even after the AI session ends. If you have any questions or need more help, please don’t hesitate to ask—I’m here for you! Sources: Connecting to LiveKit | LiveKit Docs | Development Tools | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit Docs | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py