alert-car-38551
03/12/2026, 4:07 PMtall-airline-16756
03/12/2026, 4:07 PMtall-airline-16756
03/12/2026, 4:08 PMRoomOptions and cannot be changed dynamically mid-session.
What you can do instead:
• Choose the correct model at session start. For example, set noise_cancellation.BVC() for standard WebRTC participants and noise_cancellation.BVCTelephony() for SIP participants when you create the session.
• If you must use a different noise cancellation model, end the current agent session and start a new one with the desired RoomOptions audio input configuration.
If it would help, I can show a short code example for selecting the model at session start based on participant type or outline steps for restarting a session with new settings. Which would you prefer?
Sources: Agent session | LiveKit Documentation | Using Noise Cancellation for SIP and WebRTC Participantsalert-car-38551
03/12/2026, 4:09 PMtall-airline-16756
03/12/2026, 4:09 PMawait session.shutdown(drain=True)
• To close immediately, call:
await session.aclose()
2) Create a new AgentSession (if needed)
• If you disposed the previous session object, instantiate a new AgentSession with the desired components (STT, LLM, TTS, VAD, etc.).
3) Start the session with the updated noise cancellation model
• When starting, pass the new noise-cancellation choice in `RoomOptions`:
await session.start(
room=ctx.room,
agent=Agent(instructions="You are a helpful voice AI assistant."),
room_options=room_io.RoomOptions(
audio_input=room_io.AudioInputOptions(
noise_cancellation=noise_cancellation.BVCTelephony(), # new model
),
),
)
Notes and best practices
• Noise cancellation cannot be changed mid-session; it only takes effect on session start.
• If participant type varies (WebRTC vs SIP), choose the appropriate model before starting (for example, BVC() for WebRTC, BVCTelephony() for SIP).
• Plan for a short interruption when you stop and restart the session; use shutdown(drain=True) if you need to preserve in-flight speech.
Would you like a ready-to-run code sample that includes session re-creation and safe handover (e.g., preserving any context or logs before restart)? I can tailor it to your language/runtime.
Sources: Job lifecycle | LiveKit Documentation | Agent session | LiveKit Documentation | Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Voice AI quickstart | LiveKit Documentationalert-car-38551
03/12/2026, 4:12 PMtall-airline-16756
03/12/2026, 4:12 PM# Save what matters before changing audio/session
saved_userdata = session.userdata
saved_chat_ctx = session.chat_ctx.copy()
linked_participant = session.room_io.linked_participant
saved_history = session.history # if you track full transcripts
2) Quiet I/O to avoid race conditions
# Prevent new audio from being processed while we swap filters
session.input.set_audio_enabled(False)
3) Graceful shutdown (optional) or immediate close
• To finish any in-flight speech before closing:
await session.shutdown(drain=True)
• If you need immediate restart (no draining):
await session.aclose()
4) Create/start a new session with updated noise cancellation
# Choose filter based on participant type
from livekit.plugins import noise_cancellation
from livekit import rtc
if linked_participant.kind == rtc.ParticipantKind.PARTICIPANT_KIND_SIP:
new_filter = noise_cancellation.BVCTelephony()
else:
new_filter = noise_cancellation.BVC()
# Recreate or reuse AgentSession, passing preserved state back in
new_session = AgentSession(
stt="deepgram/nova-3:en",
llm="openai/gpt-4.1-mini",
tts="cartesia/sonic-3:9626c31c-...",
vad=silero.VAD.load(),
turn_detection=MultilingualModel(),
)
await new_session.start(
room=ctx.room,
agent=Agent(instructions="You are a helpful voice AI assistant.", chat_ctx=saved_chat_ctx),
room_options=room_io.RoomOptions(
audio_input=room_io.AudioInputOptions(
noise_cancellation=new_filter
),
),
)
# Restore userdata if needed
new_session.userdata = saved_userdata
5) Re-enable audio and hand off control
new_session.input.set_audio_enabled(True)
# If you need the agent instance to switch seamlessly, you can use update_agent()
# to hand off to the new agent while preserving context:
# session.update_agent(new_agent)
Notes and best practices
• Noise cancellation cannot be hot-swapped mid-session; the change takes effect only when the session is started with the chosen RoomOptions.
• Use shutdown(drain=True) to avoid truncating the user’s last utterance when possible.
• Persist the minimal state required (chat context and userdata) to avoid replaying large histories.
• If your system links specific participant identities or attributes, preserve and re-associate them when you restart so the UX remains continuous.
• If you want zero perceptible disconnect, consider implementing a short overlap where you keep an existing session for playback/continuity while the new session initializes, then switch media routing to the new session once ready. This is more complex but reduces perceived interruption.
Would you like a ready-to-run example tailored to your exact runtime (asyncio vs. sync) or language, or would you prefer an overlap/dual-session pattern example for near-zero interruption?
Sources: Agent session | LiveKit Documentation | Agents and handoffs | LiveKit Documentation | Job lifecycle | LiveKit Documentation