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
19 changes: 10 additions & 9 deletions src/strands/event_loop/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,18 @@ def handle_content_block_stop(state: dict[str, Any]) -> dict[str, Any]:
state["text"] = ""

elif reasoning_text:
content.append(
{
"reasoningContent": {
"reasoningText": {
"text": state["reasoningText"],
"signature": state["signature"],
}
content_block: ContentBlock = {
"reasoningContent": {
"reasoningText": {
"text": state["reasoningText"],
}
}
)
}

if "signature" in state:
content_block["reasoningContent"]["reasoningText"]["signature"] = state["signature"]

content.append(content_block)
state["reasoningText"] = ""

return state
Expand Down Expand Up @@ -263,7 +265,6 @@ async def process_stream(chunks: AsyncIterable[StreamEvent]) -> AsyncGenerator[d
"text": "",
"current_tool_use": {},
"reasoningText": "",
"signature": "",
}
state["content"] = state["message"]["content"]

Expand Down
15 changes: 15 additions & 0 deletions tests/strands/event_loop/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ def test_handle_content_block_delta(event: ContentBlockDeltaEvent, state, exp_up
"signature": "123",
},
),
# Reasoning without signature
(
{
"content": [],
"current_tool_use": {},
"text": "",
"reasoningText": "test",
},
{
"content": [{"reasoningContent": {"reasoningText": {"text": "test"}}}],
"current_tool_use": {},
"text": "",
"reasoningText": "",
},
),
# Empty
(
{
Expand Down
Loading