Skip to content

Commit fbd598a

Browse files
authored
fix: only set signature in message if signature was provided by the model (#682)
1 parent 8c63d75 commit fbd598a

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

src/strands/event_loop/streaming.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,18 @@ def handle_content_block_stop(state: dict[str, Any]) -> dict[str, Any]:
194194
state["text"] = ""
195195

196196
elif reasoning_text:
197-
content.append(
198-
{
199-
"reasoningContent": {
200-
"reasoningText": {
201-
"text": state["reasoningText"],
202-
"signature": state["signature"],
203-
}
197+
content_block: ContentBlock = {
198+
"reasoningContent": {
199+
"reasoningText": {
200+
"text": state["reasoningText"],
204201
}
205202
}
206-
)
203+
}
204+
205+
if "signature" in state:
206+
content_block["reasoningContent"]["reasoningText"]["signature"] = state["signature"]
207+
208+
content.append(content_block)
207209
state["reasoningText"] = ""
208210

209211
return state
@@ -263,7 +265,6 @@ async def process_stream(chunks: AsyncIterable[StreamEvent]) -> AsyncGenerator[d
263265
"text": "",
264266
"current_tool_use": {},
265267
"reasoningText": "",
266-
"signature": "",
267268
}
268269
state["content"] = state["message"]["content"]
269270

tests/strands/event_loop/test_streaming.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ def test_handle_content_block_delta(event: ContentBlockDeltaEvent, state, exp_up
216216
"signature": "123",
217217
},
218218
),
219+
# Reasoning without signature
220+
(
221+
{
222+
"content": [],
223+
"current_tool_use": {},
224+
"text": "",
225+
"reasoningText": "test",
226+
},
227+
{
228+
"content": [{"reasoningContent": {"reasoningText": {"text": "test"}}}],
229+
"current_tool_use": {},
230+
"text": "",
231+
"reasoningText": "",
232+
},
233+
),
219234
# Empty
220235
(
221236
{

0 commit comments

Comments
 (0)