RealtimeObserver

RealtimeObserver(*, logger: Logger | None = None)
Observer for the OpenAI Realtime API.
Observer for the OpenAI Realtime API.
Parameters:
NameDescription
loggerType: logging.Logger | None

Default: None

Instance Attributes

agent



logger



realtime_client



Instance Methods

initialize_session

initialize_session(self) -> None
Initialize the session for the observer.

on_close

on_close(self) -> None
Handle close of RealtimeClient.

on_event

on_event(self, event: RealtimeEvent) -> None
Handle an event from the OpenAI Realtime API.
Parameters:
NameDescription
eventThe event from the OpenAI Realtime API.

Type: RealtimeEvent

run

run(self, agent: RealtimeAgent) -> 
Run the observer with the agent.
When implementing, be sure to call self._ready_event.set() when the observer is ready to process events.
Parameters:
NameDescription
agentThe realtime agent attached to the observer.

Type: RealtimeAgent

run_loop

run_loop(self) -> None
Run the loop if needed.
This method is called after the observer is ready to process events.
Events will be processed by the on_event method, this is just a hook for additional processing.
Use initialize_session to set up the session.

wait_for_ready

wait_for_ready(self) -> None
Get the event that is set when the observer is ready.