Skip to content

Commit 72bd289

Browse files
authored
[realtime] Add direct access to model layer from session (#1172)
1 parent 362144e commit 72bd289

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

docs/realtime/guide.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ Send audio to the session using [`session.send_audio(audio_bytes)`][agents.realt
138138

139139
For audio output, listen for `audio` events and play the audio data through your preferred audio library. Make sure to listen for `audio_interrupted` events to stop playback immediately and clear any queued audio when the user interrupts the agent.
140140

141+
## Direct model access
142+
143+
You can access the underlying model to add custom listeners or perform advanced operations:
144+
145+
```python
146+
# Add a custom listener to the model
147+
session.model.add_listener(my_custom_listener)
148+
```
149+
150+
This gives you direct access to the [`RealtimeModel`][agents.realtime.model.RealtimeModel] interface for advanced use cases where you need lower-level control over the connection.
151+
141152
## Examples
142153

143154
For complete working examples, check out the [examples/realtime directory](https://github.com/openai/openai-agents-python/tree/main/examples/realtime) which includes demos with and without UI components.

src/agents/realtime/session.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def __init__(
107107

108108
self._guardrail_tasks: set[asyncio.Task[Any]] = set()
109109

110+
@property
111+
def model(self) -> RealtimeModel:
112+
"""Access the underlying model for adding listeners or other direct interaction."""
113+
return self._model
114+
110115
async def __aenter__(self) -> RealtimeSession:
111116
"""Start the session by connecting to the model. After this, you will be able to stream
112117
events from the model and send messages and audio to the model.

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)