Should make livekit.agents.llm._FallbackRealtimeSession as public class for implementing instance check easily
Feature Type
Would make my life easier
Feature Description
In recent released version v1.6.6, a new class livekit.agents.llm._FallbackRealtimeSession is the subclass of livekit.agents.llm.RealtimeSession. Also, a existing class livekit.plugins.openai.realtime.realtime_model.RealtimeSession is the subclass of livekit.agents.llm.RealtimeSession as well.
Since openai specific realtime session event (eg. "openai_server_event_received", "openai_client_event_queued" etc. ) handlers are only allowed to be attached to livekit.plugins.openai.realtime.realtime_model.RealtimeSession, we have to check whether the realtime session object of agent is the instance of livekit.plugins.openai.realtime.realtime_model.RealtimeSession or livekit.agents.llm._FallbackRealtimeSession
If it is livekit.plugins.openai.realtime.realtime_model.RealtimeModel.RealtimeSession, we attach those openai specific realtime session event handlers to the realtime session directly.
If it is livekit.agents.llm._FallbackRealtimeSession and its active child realtime session is the instance of livekit.plugins.openai.realtime.realtime_model.RealtimeSession, we attach those openai specific realtime session event handlers to its active child realtime session instead as below:
rt_session = agent.realtime_llm_session
if isinstance(rt_session, livekit.agents.llm._FallbackRealtimeSession) and isinstance(rt_session._active, livekit.plugins.openai.realtime.realtime_model.RealtimeSession):
@rt_session._active.on("openai_server_event_received"):
def on_openai_server_event_received(event: dict[str, Any]) -> None:
....
However, since livekit.agents.llm._FallbackRealtimeSession is a private class and thus cannot import it for instance check directly.
We want livekit.agents.llm._FallbackRealtimeSession become a public class livekit.agents.llm.FallbackRealtimeSession so that we can easily import it for instance check directly.
Workarounds / Alternatives
We temporarily implement the instance check through
rt_session = agent.realtime_llm_session
if type(rt_session).__name__ == "_FallbackRealtimeSession" and isinstance(rt_session._active, livekit.plugins.openai.realtime.realtime_model.RealtimeSession):
@rt_session._active.on("openai_server_event_received"):
def on_openai_server_event_received(event: dict[str, Any]) -> None:
....
Additional Context
No response
would like to work on this