OpenAI Adapters¶
OpenAI SDK agent adapters — wraps OpenAI clients as Agents.
Note
Requires the openai extra: pip install "russo[openai]"
openai
¶
OpenAI SDK agent adapters — wraps OpenAI clients as Agents.
Provides two adapters:
- OpenAIAgent: standard Chat Completions with audio input
(
gpt-4o-audio-previewand similar models) - OpenAIRealtimeAgent: Realtime API over WebSocket
(
gpt-4o-realtime-preview)
Requires the openai package: pip install russo[openai]
OpenAIAgent
¶
OpenAIAgent(*, client: Any, model: str = 'gpt-4o-audio-preview', tools: list[Any] | None = None, system_prompt: str | None = None, extra_create_kwargs: dict[str, Any] | None = None)
Agent adapter that wraps an AsyncOpenAI client for Chat Completions.
Sends audio via the Chat Completions API and auto-parses tool-call
responses with :class:OpenAIResponseParser.
Usage::
from openai import AsyncOpenAI
client = AsyncOpenAI()
agent = OpenAIAgent(
client=client,
model="gpt-4o-audio-preview",
tools=[{
"type": "function",
"function": {
"name": "book_flight",
"parameters": {"type": "object", "properties": {...}},
},
}],
)
response = await agent.run(audio)
| PARAMETER | DESCRIPTION |
|---|---|
client
|
An
TYPE:
|
model
|
Model name supporting audio input.
TYPE:
|
tools
|
OpenAI tool definitions (function-calling format).
TYPE:
|
system_prompt
|
Optional system message prepended to the conversation.
TYPE:
|
extra_create_kwargs
|
Additional kwargs forwarded to
TYPE:
|
Source code in src/russo/adapters/openai.py
run
async
¶
run(audio: Audio) -> AgentResponse
Send audio via Chat Completions and parse the tool-call response.
Source code in src/russo/adapters/openai.py
OpenAIRealtimeAgent
¶
OpenAIRealtimeAgent(*, client: Any | None = None, connection: Any | None = None, model: str = 'gpt-4o-realtime-preview', tools: list[Any] | None = None, response_timeout: float = 30.0)
Agent adapter for OpenAI's Realtime API.
Connects via the SDK's client.beta.realtime.connect() interface,
sends audio, and collects response.function_call_arguments.done events.
Accepts either:
- An
AsyncOpenAIclient (creates a new connection perrun()) - A pre-existing realtime connection (reuses it, no session config sent)
Usage with client::
from openai import AsyncOpenAI
client = AsyncOpenAI()
agent = OpenAIRealtimeAgent(
client=client,
model="gpt-4o-realtime-preview",
tools=[{
"type": "function",
"name": "book_flight",
"description": "Book a flight",
"parameters": {"type": "object", "properties": {...}},
}],
)
response = await agent.run(audio)
Usage with pre-existing connection::
async with client.beta.realtime.connect(model="gpt-4o-realtime-preview") as conn:
agent = OpenAIRealtimeAgent(connection=conn)
response = await agent.run(audio)
Note
The Realtime API expects pcm16 audio at 24 kHz mono by default. If you pass WAV audio, the adapter automatically strips the WAV header to extract raw PCM frames.
| PARAMETER | DESCRIPTION |
|---|---|
client
|
An
TYPE:
|
connection
|
A pre-existing realtime connection (from
TYPE:
|
model
|
Realtime model name.
TYPE:
|
tools
|
Tool definitions sent during session configuration.
TYPE:
|
response_timeout
|
Max seconds to wait for a complete response.
TYPE:
|
Source code in src/russo/adapters/openai.py
run
async
¶
run(audio: Audio) -> AgentResponse
Send audio via the Realtime API and collect function calls.