> ## 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.RealtimeObserver

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

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

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

Observer for the OpenAI Realtime API.<br />Observer for the OpenAI Realtime API.<br />

<b>Parameters:</b>

| Name     | Description                                                   |
| -------- | ------------------------------------------------------------- |
| `logger` | **Type:** logging.Logger \| None<br /><br />**Default:** None |

### Instance Attributes

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

#### agent

<br />

<br />

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

#### logger

<br />

<br />

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

#### realtime\_client

<br />

<br />

### Instance Methods

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

#### initialize\_session

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

Initialize the session for the observer.

<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 an event 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](/docs/api-reference/autogen/agentchat/realtime/experimental/RealtimeAgent) |

<br />

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

#### run\_loop

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

Run the loop if needed.<br />This method is called after the observer is ready to process events.<br />Events will be processed by the on\_event method, this is just a hook for additional processing.<br />Use initialize\_session to set up the session.

<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 />
