Skip to content
Open
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
7 changes: 5 additions & 2 deletions src/strands/models/sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,10 @@ async def stream(
)

# Handle reasoning content
if choice["delta"].get("reasoning_content"):
# NOTE: Both `reasoning` and `reasoning_content` need to be handled as vLLM v0.16.0 deprecated
# the `reasoning_content` in favour of `reasoning`
# See https://github.com/vllm-project/vllm/pull/33402
if any(k in choice["delta"] for k in {"reasoning_content", "reasoning"}):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: The condition checks for key existence but not value truthiness. If vLLM sends "reasoning": None or "reasoning": "" in the delta (common in streaming when the key is present but no reasoning content is being sent on that chunk), this will enter the block and emit an empty/None delta.

Compare with the text content check on line 358 which uses .get("content") (truthy check), and the OpenAI provider which uses choice.delta.reasoning_content (also truthy).

Suggestion: Use a truthiness check consistent with the rest of the codebase:

reasoning_text = choice["delta"].get("reasoning_content") or choice["delta"].get("reasoning")
if reasoning_text:

This also simplifies line 385 since the value is already extracted.

if not reasoning_content_started:
yield self.format_chunk(
{"chunk_type": "content_start", "data_type": "reasoning_content"}
Expand All @@ -379,7 +382,7 @@ async def stream(
{
"chunk_type": "content_delta",
"data_type": "reasoning_content",
"data": choice["delta"]["reasoning_content"],
"data": choice["delta"].get("reasoning_content", choice["delta"].get("reasoning")),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: dict.get(key, default) returns None when the key exists with value None—the default is only used when the key is missing. If a response contains {"reasoning_content": None, "reasoning": "actual text"}, this expression returns None instead of "actual text".

Suggestion: Use or for a falsy-fallback:

"data": choice["delta"].get("reasoning_content") or choice["delta"].get("reasoning"),

}
)

Expand Down
Loading