Fix toolInUse initialization to correctly detect tool usage#425
Open
Nepomuk5665 wants to merge 1 commit intoawslabs:mainfrom
Open
Fix toolInUse initialization to correctly detect tool usage#425Nepomuk5665 wants to merge 1 commit intoawslabs:mainfrom
Nepomuk5665 wants to merge 1 commit intoawslabs:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug in
bedrock_llm_agent.pywhere thetoolInUsevariable was incorrectly initialized toTruebefore the loop that checks for tool usage, making it alwaysTrueregardless of whether a tool was actually used.Bug Description
In both
handle_single_responseandhandle_streaming_responsemethods:This caused
reasoningContent(thinking content) to always be inserted at index 0 of the content array, even when no tool was being used. According to the code comment, reasoning content should only be inserted at index 0 when a tool is used, and appended otherwise.Fix
toolInUse = TruetotoolInUse = Falseto correctly initialize the variablethinking_content/accumulated_thinkingbefore appending to avoid appendingNonevalues when there is no thinking contentImpact
When extended thinking is enabled and no tool is used, the
reasoningContentwill now be correctly appended to the content array instead of being inserted at the beginning.