From 6dd9b6d7aebd861beb4b1ce647a779c469f7120c Mon Sep 17 00:00:00 2001 From: Nepomuk Crhonek <105591323+Nepomuk5665@users.noreply.github.com> Date: Sat, 24 Jan 2026 00:11:28 +0100 Subject: [PATCH] Fix toolInUse initialization to correctly detect tool usage The toolInUse variable was incorrectly initialized to True before the loop that checks for tool usage, making it always True regardless of whether a tool was actually used. This caused reasoningContent to always be inserted at index 0 instead of being appended when no tool is used. Also added a check for thinking_content/accumulated_thinking before appending to avoid appending None values when there is no thinking content. --- python/src/agent_squad/agents/bedrock_llm_agent.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/src/agent_squad/agents/bedrock_llm_agent.py b/python/src/agent_squad/agents/bedrock_llm_agent.py index 9138cb8a..10552151 100644 --- a/python/src/agent_squad/agents/bedrock_llm_agent.py +++ b/python/src/agent_squad/agents/bedrock_llm_agent.py @@ -387,8 +387,8 @@ async def handle_single_response( if isinstance(item, dict) and "text" in item: content.append(item) - toolInUse=True - # Go through response content and save text items + toolInUse = False + # Go through response content and save toolUse items for item in response_content: if isinstance(item, dict) and "toolUse" in item: content.append(item) @@ -398,7 +398,7 @@ async def handle_single_response( if toolInUse: if thinking_content: content.insert(0,{"reasoningContent": thinking_content}) - else: + elif thinking_content: content.append({"reasoningContent": thinking_content}) kwargs = { @@ -520,8 +520,8 @@ async def handle_streaming_response( if isinstance(item, dict) and "text" in item: _content.append(item) - toolInUse=True - # Go through response content and save text items + toolInUse = False + # Go through response content and save toolUse items for item in response_content: if isinstance(item, dict) and "toolUse" in item: _content.append(item) @@ -531,7 +531,7 @@ async def handle_streaming_response( if toolInUse: if accumulated_thinking: _content.insert(0,{"reasoningContent": {"reasoningText": {"text": accumulated_thinking, "signature":thinking_signature}}}) - else: + elif accumulated_thinking: _content.append({"reasoningContent": {"reasoningText": {"text": accumulated_thinking, "signature":thinking_signature}}})