Skip to content

Commit 4c191ff

Browse files
Python: fix(devui): fallback to empty string when reasoning chunk has no text (#9546)
* fix(devui): fallback to empty string when reasoning chunk has no text Fixes #9533 * test(devui): initialize reasoning sequence counters
1 parent 1fe5467 commit 4c191ff

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎python/packages/devui/agent_framework_devui/_mapper.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ async def _map_reasoning_content(self, content: Any, context: dict[str, Any]) ->
14321432
"""Map TextReasoningContent to ResponseReasoningTextDeltaEvent."""
14331433
return ResponseReasoningTextDeltaEvent(
14341434
type="response.reasoning_text.delta",
1435-
delta=content.text,
1435+
delta=content.text or "",
14361436
item_id=context["item_id"],
14371437
output_index=context["output_index"],
14381438
content_index=context["content_index"],

‎python/packages/devui/tests/devui/test_mapper.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,3 +1179,34 @@ async def test_superstep_completed_event(mapper: MessageMapper, test_request: Ag
11791179
# superstep_completed event (type='superstep_completed') may not emit events (internal workflow signal)
11801180
# Just ensure it doesn't crash
11811181
assert isinstance(events, list)
1182+
1183+
1184+
# =============================================================================
1185+
# Reasoning Content Tests
1186+
# =============================================================================
1187+
1188+
1189+
async def test_map_reasoning_content_with_none_text(mapper: MessageMapper) -> None:
1190+
"""Test that TextReasoningContent with None text falls back to empty string without raising validation error."""
1191+
from unittest.mock import MagicMock
1192+
1193+
context = {"item_id": "item-1", "output_index": 0, "content_index": 0, "sequence_counter": 0}
1194+
content = MagicMock()
1195+
content.text = None
1196+
1197+
event = await mapper._map_reasoning_content(content, context)
1198+
assert event.type == "response.reasoning_text.delta"
1199+
assert event.delta == ""
1200+
1201+
1202+
async def test_map_reasoning_content_with_valid_text(mapper: MessageMapper) -> None:
1203+
"""Test that TextReasoningContent with valid text maps delta properly."""
1204+
from unittest.mock import MagicMock
1205+
1206+
context = {"item_id": "item-1", "output_index": 0, "content_index": 0, "sequence_counter": 0}
1207+
content = MagicMock()
1208+
content.text = "Thinking through the steps..."
1209+
1210+
event = await mapper._map_reasoning_content(content, context)
1211+
assert event.type == "response.reasoning_text.delta"
1212+
assert event.delta == "Thinking through the steps..."

0 commit comments

Comments
 (0)