Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/strands/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _find_normalized_tool_name(self, name: str) -> str:
"""Lookup the tool represented by name, replacing characters with underscores as necessary."""
tool_registry = self._agent.tool_registry.registry

if tool_registry.get(name, None):
if tool_registry.get(name):
return name

# If the desired name contains underscores, it might be a placeholder for characters that can't be
Expand Down
18 changes: 9 additions & 9 deletions src/strands/models/sagemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ async def stream(
logger.info("choice=<%s>", json.dumps(choice, indent=2))

# Handle text content
if choice["delta"].get("content", None):
if choice["delta"].get("content"):
if not text_content_started:
yield self.format_chunk({"chunk_type": "content_start", "data_type": "text"})
text_content_started = True
Expand All @@ -357,7 +357,7 @@ async def stream(
)

# Handle reasoning content
if choice["delta"].get("reasoning_content", None):
if choice["delta"].get("reasoning_content"):
if not reasoning_content_started:
yield self.format_chunk(
{"chunk_type": "content_start", "data_type": "reasoning_content"}
Expand All @@ -382,7 +382,7 @@ async def stream(
finish_reason = choice["finish_reason"]
break

if choice.get("usage", None):
if choice.get("usage"):
yield self.format_chunk(
{"chunk_type": "metadata", "data": UsageMetadata(**choice["usage"])}
)
Expand All @@ -402,7 +402,7 @@ async def stream(
# Handle tool calling
logger.info("tool_calls=<%s>", json.dumps(tool_calls, indent=2))
for tool_deltas in tool_calls.values():
if not tool_deltas[0]["function"].get("name", None):
if not tool_deltas[0]["function"].get("name"):
raise Exception("The model did not provide a tool name.")
yield self.format_chunk(
{"chunk_type": "content_start", "data_type": "tool", "data": ToolCall(**tool_deltas[0])}
Expand Down Expand Up @@ -443,7 +443,7 @@ async def stream(
yield self.format_chunk({"chunk_type": "content_stop", "data_type": "text"})

# Handle reasoning content
if message.get("reasoning_content", None):
if message.get("reasoning_content"):
yield self.format_chunk({"chunk_type": "content_start", "data_type": "reasoning_content"})
yield self.format_chunk(
{
Expand All @@ -455,7 +455,7 @@ async def stream(
yield self.format_chunk({"chunk_type": "content_stop", "data_type": "reasoning_content"})

# Handle the tool calling, if any
if message.get("tool_calls", None) or message_stop_reason == "tool_calls":
if message.get("tool_calls") or message_stop_reason == "tool_calls":
if not isinstance(message["tool_calls"], list):
message["tool_calls"] = [message["tool_calls"]]
for tool_call in message["tool_calls"]:
Expand All @@ -474,9 +474,9 @@ async def stream(
# Message close
yield self.format_chunk({"chunk_type": "message_stop", "data": message_stop_reason})
# Handle usage metadata
if final_response_json.get("usage", None):
if final_response_json.get("usage"):
yield self.format_chunk(
{"chunk_type": "metadata", "data": UsageMetadata(**final_response_json.get("usage", None))}
{"chunk_type": "metadata", "data": UsageMetadata(**final_response_json.get("usage"))}
)
except (
self.client.exceptions.InternalFailure,
Expand Down Expand Up @@ -544,7 +544,7 @@ def format_request_message_content(cls, content: ContentBlock) -> dict[str, Any]
"thinking": content["reasoningContent"].get("reasoningText", {}).get("text", ""),
"type": "thinking",
}
elif not content.get("reasoningContent", None):
elif not content.get("reasoningContent"):
content.pop("reasoningContent", None)

if "video" in content:
Expand Down