Skip to content

Commit 04441c2

Browse files
committed
fix(streaming): ensure process_stream returns non-empty message content
1 parent eaa6efb commit 04441c2

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/strands/event_loop/streaming.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,9 @@ async def process_stream(
413413
elif "redactContent" in chunk:
414414
handle_redact_content(chunk["redactContent"], state)
415415

416+
if not state["message"]["content"]:
417+
state["message"]["content"].append({"text": ""})
418+
416419
yield ModelStopReason(stop_reason=stop_reason, message=state["message"], usage=usage, metrics=metrics)
417420

418421

tests/strands/event_loop/test_streaming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ def test_extract_usage_metrics_empty_metadata():
578578
"end_turn",
579579
{
580580
"role": "assistant",
581-
"content": [],
581+
"content": [{"text": ""}],
582582
},
583583
{"inputTokens": 0, "outputTokens": 0, "totalTokens": 0},
584584
{"latencyMs": 0, "timeToFirstByteMs": 0},

0 commit comments

Comments
 (0)