Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/agents/realtime/openai_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ async def _handle_ws_event(self, event: dict[str, Any]):
"transcript": part.get("transcript"),
}
)
elif part.get("type") == "text":
elif part.get("type") in ("text", "output_text"):
converted_content.append({"type": "text", "text": part.get("text")})
status = item.get("status")
if status not in ("in_progress", "completed", "incomplete"):
Expand Down
33 changes: 33 additions & 0 deletions tests/realtime/test_openai_realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,39 @@ async def test_backward_compat_output_item_added_and_done(self, model):
types = [c[0][0].type for c in listener.on_event.call_args_list]
assert types.count("item_updated") >= 2

@pytest.mark.asyncio
async def test_text_mode_output_item_content(self, model):
"""output_text content is properly handled in message items."""
listener = AsyncMock()
model.add_listener(listener)

msg_added = {
"type": "response.output_item.added",
"item": {
"id": "text_item_1",
"type": "message",
"role": "assistant",
"content": [
{"type": "output_text", "text": "test data"},
],
},
}
await model._handle_ws_event(msg_added)

# Verify the item was updated with content
assert listener.on_event.call_count >= 2
item_updated_calls = [
call for call in listener.on_event.call_args_list if call[0][0].type == "item_updated"
]
assert len(item_updated_calls) >= 1

item = item_updated_calls[0][0][0].item
assert item.type == "message"
assert item.role == "assistant"
assert len(item.content) >= 1
assert item.content[0].type == "text"
assert item.content[0].text == "test data"

# Note: response.created/done require full OpenAI response payload which is
# out-of-scope for unit tests here; covered indirectly via other branches.

Expand Down