Skip to content

Commit c4ed605

Browse files
authored
fix: #2161 handle output_text type in realtime text mode (#2235)
1 parent 007a65c commit c4ed605

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/agents/realtime/openai_realtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ async def _handle_ws_event(self, event: dict[str, Any]):
571571
"transcript": part.get("transcript"),
572572
}
573573
)
574-
elif part.get("type") == "text":
574+
elif part.get("type") in ("text", "output_text"):
575575
converted_content.append({"type": "text", "text": part.get("text")})
576576
status = item.get("status")
577577
if status not in ("in_progress", "completed", "incomplete"):

tests/realtime/test_openai_realtime.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,39 @@ async def test_backward_compat_output_item_added_and_done(self, model):
473473
types = [c[0][0].type for c in listener.on_event.call_args_list]
474474
assert types.count("item_updated") >= 2
475475

476+
@pytest.mark.asyncio
477+
async def test_text_mode_output_item_content(self, model):
478+
"""output_text content is properly handled in message items."""
479+
listener = AsyncMock()
480+
model.add_listener(listener)
481+
482+
msg_added = {
483+
"type": "response.output_item.added",
484+
"item": {
485+
"id": "text_item_1",
486+
"type": "message",
487+
"role": "assistant",
488+
"content": [
489+
{"type": "output_text", "text": "test data"},
490+
],
491+
},
492+
}
493+
await model._handle_ws_event(msg_added)
494+
495+
# Verify the item was updated with content
496+
assert listener.on_event.call_count >= 2
497+
item_updated_calls = [
498+
call for call in listener.on_event.call_args_list if call[0][0].type == "item_updated"
499+
]
500+
assert len(item_updated_calls) >= 1
501+
502+
item = item_updated_calls[0][0][0].item
503+
assert item.type == "message"
504+
assert item.role == "assistant"
505+
assert len(item.content) >= 1
506+
assert item.content[0].type == "text"
507+
assert item.content[0].text == "test data"
508+
476509
# Note: response.created/done require full OpenAI response payload which is
477510
# out-of-scope for unit tests here; covered indirectly via other branches.
478511

0 commit comments

Comments
 (0)