Key Changes
WebSocket Mode for OpenAI Responses API
This version adds WebSocket mode support for OpenAI's Responses API. This is a new opt-in feature, so the default behavior is unchanged. If you want to switch all Responses API calls to WebSocket mode, call set_default_openai_responses_transport("websocket") to enable it for all OpenAI Responses model agents.
You can also use either OpenAIProvider along with use_responses_websocket=True or responses_websocket_session() utility to enable a reusable WebSocket connection, as shown below:
import asyncio
from agents import Agent, responses_websocket_session
async def main():
agent = Agent(name="Assistant", instructions="Be concise.")
async with responses_websocket_session() as ws:
first = ws.run_streamed(agent, "Say hello in one short sentence.")
async for _event in first.stream_events():
pass
second = ws.run_streamed(
agent,
"Now say goodbye.",
previous_response_id=first.last_response_id,
)
async for _event in second.stream_events():
pass
asyncio.run(main())References:
What's Changed
- feat: add Responses websocket model and stream_ws example by @seratch in #2530
- fix: drop usage token detail fields from OpenAI trace ingest payloads by @seratch in #2529
Documents & Other Changes
- docs: add missing changes by @seratch in #2526
- docs: update translated document pages by @github-actions[bot] in #2527
- Release 0.10.0 by @github-actions[bot] in #2532
Full Changelog: v0.9.3...v0.10.0