agents icon indicating copy to clipboard operation
agents copied to clipboard

all attached plugin-specific realtime session event handlers lost when retart_session with the same model.

Open moz164164 opened this issue 4 months ago • 0 comments

Bug Description

According to deepwiki https://deepwiki.com/search/can-fallbackrealtimesession-im_15e6ca5e-6280-4091-b3d6-65ddfb72aedf?mode=deep, for livekit.agents.llm.RealtimeModelAapter, openai specific realtime session event handlers are attached to its child realtime session and handlers for general reatime session event in https://github.com/livekit/agents/blob/87ef1b15f11239fa1e4cec9f6eace72b71904830/livekit-agents/livekit/agents/llm/realtime_fallback_adapter.py#L58 ) are forwarded to attached to its parent realtime session.

According to source codes, when implementing llm.restart_session(switch_model=False) , its old child realtime session are closed and discarded and its parent realtime session only keep those handlers of those general realtime session event, and thus all attached plugin-specific realtime session event handlers (eg. openai specific realtime event handlers etc.) will lose

We think this is not a right behavior since you mentioned livekit.agents.llm.RealtimeModelAapter will preserve the agent's bound event handlers in PR https://github.com/livekit/agents/pull/6282.

Please correct the source code so that all attached plugin-specific realtime session event handlers should be automatically forwarded to the new child realtime session if llm.restart_session(switch_model=False) is implemented.

Expected Behavior

all attached plugin-specific realtime session event handlers should be automatically forwarded to the new child realtime session if llm.restart_session(switch_model=False) is implemented.

Reproduction Steps

  1. set
llm=RealtimeModelFallbackAdapter(
 [openai.realtime.RealtimeModel(),
openai.realtime.RealtimeModel.with_azure()]
)
  1. attach openai-specific realtime session event handlers:
   rt_session = agent.realtime_llm_session
   @rt_session._active.on("openai_server_event_received")
   def on_openai_server_event_received(event: dict[str, Any]) -> None:
        logger.info("openai_server_event_received handling"
  1. implement
await agent.llm.restart_session(switch_model=False)
  1. try to simulate to emit "openai_server_event_received" realtime session event
  2. check whether the attached openai-specific realtime session event handlers still work

Operating System

MacOS, linux

Models Used

Openai gpt-realtime, Azure gpt-realtime

Package Versions

livekit=1.1.13
livekit-agents=1.6.6
livekit-api=1.2.0

Session/Room/Call IDs

No response

Proposed Solution


Additional Context

No response

Screenshots and Recordings

No response

moz164164 avatar Jul 27 '26 07:07 moz164164