Lightweight framework for building multi-agent workflows with LLMs, supporting handoffs, guardrails, tools, and 100+ LLM providers
The Realtime API enables real-time audio/voice agent interactions with event-driven architecture. This allows building voice assistants, phone systems, and other real-time conversational AI applications.
The Realtime API provides:
Agent configured for real-time audio interactions.
class RealtimeAgent:
"""
Agent for real-time audio interactions.
Extends AgentBase with real-time specific configuration
for voice conversations.
"""Usage example:
from agents.realtime import RealtimeAgent
agent = RealtimeAgent(
name="Voice Assistant",
instructions="You are a helpful voice assistant."
)Runner for executing realtime agents.
class RealtimeRunner:
"""Runner for realtime agents."""
@classmethod
async def run(
starting_agent: RealtimeAgent,
*,
session: RealtimeSession,
context = None,
hooks = None,
config = None
):
"""
Run realtime agent.
Parameters:
- starting_agent: Realtime agent to run
- session: Realtime session for audio
- context: Optional context object
- hooks: Lifecycle hooks
- config: Configuration options
Returns:
- Realtime result
"""Usage example:
from agents.realtime import RealtimeAgent, RealtimeRunner, RealtimeSession
agent = RealtimeAgent(
name="Voice Assistant",
instructions="Help users via voice."
)
session = RealtimeSession(...) # Configure session
result = await RealtimeRunner.run(
agent,
session=session
)Session for managing real-time audio interactions.
class RealtimeSession:
"""
Session for realtime interactions.
Manages audio streaming, turn detection,
and real-time events.
"""Event types emitted during real-time execution (specific event types depend on the implementation).
Basic command-line voice assistant:
# See examples/realtime/cli/demo.py in the repository
from agents.realtime import RealtimeAgent, RealtimeRunner
agent = RealtimeAgent(
name="CLI Assistant",
instructions="You are a voice assistant."
)
# Run with audio I/O
result = await RealtimeRunner.run(agent, session=cli_session)Integration with Twilio for phone-based agents:
# See examples/realtime/twilio/server.py in the repository
from agents.realtime import RealtimeAgent
phone_agent = RealtimeAgent(
name="Phone Assistant",
instructions="You are a phone assistant. Be concise."
)
# Integrate with Twilio websocket
# See repository examples for complete implementationReal-time voice in web applications:
# See examples/realtime/app/server.py in the repository
from agents.realtime import RealtimeAgent
web_agent = RealtimeAgent(
name="Web Assistant",
instructions="You are a web-based voice assistant."
)
# Connect to WebSocket for browser audio
# See repository examples for complete implementationAutomatic detection of when user is speaking.
Automatic turn-taking between user and agent.
Real-time function/tool calling during conversation.
Bidirectional audio streaming for low-latency interactions.
Complete working examples are available in the repository:
examples/realtime/cli/demo.py - CLI voice assistantexamples/realtime/app/server.py - Web application integrationexamples/realtime/twilio/server.py - Twilio phone integrationexamples/realtime/twilio_sip/server.py - Twilio SIP integrationRefer to these examples for complete implementation details.
The Realtime API is a specialized feature for voice applications. Most use cases should use the standard Agent and Runner classes. Use Realtime API when you specifically need:
For complete API reference and implementation details, refer to the source code and examples in the repository.
Install with Tessl CLI
npx tessl i tessl/pypi-openai-agents