Text content block is silently dropped when a toolUse is pending in the same content block stop
Summary
handle_content_block_stop in strands-py/src/strands/event_loop/streaming.py uses an elif chain, so when a content block stops with both a pending current_tool_use and accumulated text, the text is silently discarded — never appended to the assistant message, and left stranded in state["text"].
This is the same defect class as #1394 (reasoning vs. text), for a different pair of branches.
Current code (main, and 1.53.0)
if current_tool_use:
...
content.append({"toolUse": tool_use})
state["current_tool_use"] = {}
elif text: # <-- elif
...
content.append({"text": text})
state["text"] = ""
elif reasoning_text or "signature" in state:
...Reproduction
Calling the real function with both a tool use and text pending:
from strands.event_loop.streaming import handle_content_block_stop
# A. text alone — works
state = {"content": [], "current_tool_use": {}, "text": "Let me check that for you.",
"reasoningText": "", "citationsContent": [], "redactedContent": None}
handle_content_block_stop(state)
# content -> [{'text': 'Let me check that for you.'}] leftover text -> ''
# B. text AND a pending tool use — text is dropped
state = {"content": [],
"current_tool_use": {"toolUseId": "t1", "name": "read_file", "input": "{}"},
"text": "Let me check that for you.",
"reasoningText": "", "citationsContent": [], "redactedContent": None}
handle_content_block_stop(state)
# content -> [{'toolUse': {...}}] leftover text -> 'Let me check that for you.'
# ^ never appended, never clearedWhy it matters
A model that streams a short preamble and then calls a tool in the same assistant turn ("Let me check that for you." → toolUse) has that preamble delivered to the client but absent from the assistant message in conversation history. Every later reader of that history — a subsequent model pass, a session snapshot/restore, a transcript view, a replay — sees a turn in which the assistant said nothing before calling the tool.
I want to be precise about what I am and am not claiming: I can demonstrate the drop by executing the function, as above. I am reporting the code defect, not attributing a specific user-visible symptom to it — in our own investigation we initially believed it explained a duplicated-preamble bug, and on closer measurement the text was intact in that particular case and the duplication had another cause. The dropped-text path is real and demonstrable; how often a given provider hits it depends on whether that provider emits the text in its own content block before opening the tool block.
Precedent
- #1394 — same
elifchain, reasoning vs. text. - #1395 — changed the branches to independent
ifstatements. Reviewed positively as a "foundational fix that benefits all providers", then closed unmerged with "the issue seems to be closed now, fixed with #1557." - #1557 — merged, but it only changes
models/gemini.pyso that provider never emits both types at onecontentBlockStop. The genericelifinstreaming.pywas not touched.
So the reasoning-vs-text case was resolved provider-side, and the generic handler still drops one of two co-pending content types. The current_tool_use vs text pair has no provider-side mitigation that I could find.
Suggested fix
The approach in #1395 — make the branches independent ifs rather than elifs — resolves this pair and the reasoning pair together, in one place, for all providers. That patch already exists and already has a favourable review.
Environment
strands-agents1.30.0 (verified in installed source) and 1.53.0 / currentmain(verified via raw GitHub source) — the branch structure is unchanged between them.- Reproduced on Python 3.13.
Source: strands-agents/harness-sdk