FunctionObserver

FunctionObserver(*, logger: ForwardRef('Logger') | None = None)

Observer for handling function calls from the OpenAI Realtime API.
Observer for handling function calls from the OpenAI Realtime API.

Parameters:
NameDescription
loggerType: ForwardRef(‘Logger’) | None

Default: None

Instance Methods

call_function

call_function(
    self,
    call_id: str,
    name: str,
    kwargs: dict[str, Any]
) -> None

Call a function registered with the agent.

Parameters:
NameDescription
call_idThe ID of the function call.

Type: str
nameThe name of the function to call.

Type: str
kwargsThe arguments to pass to the function.

Type: dict[str, typing.Any]

initialize_session

initialize_session(self) -> None

Add registered tools to OpenAI with a session update.


on_close

on_close(self) -> None

Handle close of RealtimeClient.


on_event

on_event(self, event: RealtimeEvent) -> None

Handle function call events 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 observer loop.


wait_for_ready

wait_for_ready(self) -> None

Get the event that is set when the observer is ready.