> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ag2.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# autogen.agentchat.realtime.experimental.FunctionObserver

<h2 id="autogen.agentchat.realtime.experimental.FunctionObserver" class="doc doc-heading">
  <code class="doc-symbol doc-symbol-heading doc-symbol-class" />

  <span class="doc doc-object-name doc-class-name">FunctionObserver</span>
</h2>

```python theme={null}
FunctionObserver(*, logger: ForwardRef('Logger') | None = None)
```

Observer for handling function calls from the OpenAI Realtime API.<br />Observer for handling function calls from the OpenAI Realtime API.

<b>Parameters:</b>

| Name     | Description                                                         |
| -------- | ------------------------------------------------------------------- |
| `logger` | **Type:** ForwardRef('Logger') \| None<br /><br />**Default:** None |

### Instance Methods

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### call\_function

```python theme={null}
call_function(
    self,
    call_id: str,
    name: str,
    kwargs: dict[str, Any]
) -> None
```

Call a function registered with the agent.<br />

<b>Parameters:</b>

| Name      | Description                                                                        |
| --------- | ---------------------------------------------------------------------------------- |
| `call_id` | The ID of the function call.<br /><br />**Type:** str                              |
| `name`    | The name of the function to call.<br /><br />**Type:** str                         |
| `kwargs`  | The arguments to pass to the function.<br /><br />**Type:** dict\[str, typing.Any] |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### initialize\_session

```python theme={null}
initialize_session(self) -> None
```

Add registered tools to OpenAI with a session update.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### on\_close

```python theme={null}
on_close(self) -> None
```

Handle close of RealtimeClient.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### on\_event

```python theme={null}
on_event(self, event: RealtimeEvent) -> None
```

Handle function call events from the OpenAI Realtime API.<br />

<b>Parameters:</b>

| Name    | Description                                                                                                                                                             |
| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `event` | The event from the OpenAI Realtime API.<br /><br />**Type:** [RealtimeEvent](/docs/api-reference/autogen/agentchat/realtime/experimental/realtime_events/RealtimeEvent) |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### run

```python theme={null}
run(self, agent: RealtimeAgent) -> 
```

Run the observer with the agent.<br />When implementing, be sure to call `self._ready_event.set()` when the observer is ready to process events.<br />

<b>Parameters:</b>

| Name    | Description                                                                     |
| ------- | ------------------------------------------------------------------------------- |
| `agent` | The realtime agent attached to the observer.<br /><br />**Type:** RealtimeAgent |

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### run\_loop

```python theme={null}
run_loop(self) -> None
```

Run the observer loop.

<br />

<code class="doc-symbol doc-symbol-heading doc-symbol-method" />

#### wait\_for\_ready

```python theme={null}
wait_for_ready(self) -> None
```

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

<br />
