Model
RealtimePlaybackState
Bases: TypedDict
Source code in src/agents/realtime/model.py
current_item_id
instance-attribute
The item ID of the current item being played.
current_item_content_index
instance-attribute
The index of the current item content being played.
RealtimePlaybackTracker
If you have custom playback logic or expect that audio is played with delays or at different
speeds, create an instance of RealtimePlaybackTracker and pass it to the session. You are
responsible for tracking the audio playback progress and calling on_play_bytes
or
on_play_ms
when the user has played some audio.
Source code in src/agents/realtime/model.py
on_play_bytes
Called by you when you have played some audio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_id
|
str
|
The item ID of the audio being played. |
required |
item_content_index
|
int
|
The index of the audio content in |
required |
bytes
|
bytes
|
The audio bytes that have been fully played. |
required |
Source code in src/agents/realtime/model.py
on_play_ms
Called by you when you have played some audio.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item_id
|
str
|
The item ID of the audio being played. |
required |
item_content_index
|
int
|
The index of the audio content in |
required |
ms
|
float
|
The number of milliseconds of audio that have been played. |
required |
Source code in src/agents/realtime/model.py
on_interrupted
set_audio_format
set_audio_format(format: RealtimeAudioFormat) -> None
Will be called by the model to set the audio format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
format
|
RealtimeAudioFormat
|
The audio format to use. |
required |
get_state
get_state() -> RealtimePlaybackState
Will be called by the model to get the current playback state.
Source code in src/agents/realtime/model.py
RealtimeModelListener
Bases: ABC
A listener for realtime transport events.
Source code in src/agents/realtime/model.py
on_event
abstractmethod
async
RealtimeModelConfig
Bases: TypedDict
Options for connecting to a realtime model.
Source code in src/agents/realtime/model.py
api_key
instance-attribute
The API key (or function that returns a key) to use when connecting. If unset, the model will
try to use a sane default. For example, the OpenAI Realtime model will try to use the
OPENAI_API_KEY
environment variable.
url
instance-attribute
The URL to use when connecting. If unset, the model will use a sane default. For example, the OpenAI Realtime model will use the default OpenAI WebSocket URL.
initial_model_settings
instance-attribute
initial_model_settings: NotRequired[
RealtimeSessionModelSettings
]
The initial model settings to use when connecting.
playback_tracker
instance-attribute
playback_tracker: NotRequired[RealtimePlaybackTracker]
The playback tracker to use when tracking audio playback progress. If not set, the model will use a default implementation that assumes audio is played immediately, at realtime speed.
A playback tracker is useful for interruptions. The model generates audio much faster than realtime playback speed. So if there's an interruption, its useful for the model to know how much of the audio has been played by the user. In low-latency scenarios, it's fine to assume that audio is played back immediately at realtime speed. But in scenarios like phone calls or other remote interactions, you can set a playback tracker that lets the model know when audio is played to the user.
RealtimeModel
Bases: ABC
Interface for connecting to a realtime model and sending/receiving events.
Source code in src/agents/realtime/model.py
connect
abstractmethod
async
connect(options: RealtimeModelConfig) -> None
add_listener
abstractmethod
add_listener(listener: RealtimeModelListener) -> None
remove_listener
abstractmethod
remove_listener(listener: RealtimeModelListener) -> None