fix(bedrock-converse): Improve handling of reasoningContent in responses from Converse & ConverStream requests#20853
Open
mattref wants to merge 1 commit intorun-llama:mainfrom
Open
Conversation
…ses from Converse & ConverStream requests Resolves run-llama#20851 by fixing a regression introduced in run-llama#20664 that caused certain fields within `reasoningContent`, such as `signature`, to not be captured as expected when using the Bedrock Converse/ConverseStream APIs. PR run-llama#20664 was merged via commit: cf1b558
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.
Description
Fixes #20851 by addressing a regression introduced in #20664 that caused certain fields within
reasoningContent, such assignature, to not be captured as expected when using the Bedrock Converse/ConverseStream APIs. This renders certain usage of BedrockConverse unusable, such as using the LLM with extended thinking and tool calling.The changes in this PR were made to stay aligned with the Converse/ConverseStream specifications.
As part of the review of #20664 , a variety of changes were made that ultimately left the PR in a state where no new behaviors were being introduced. Additionally, as mentioned in my comment on #20851 , I also noticed that #20664 introduced some changes that aren't clear. For example, the added
extract_thinking_from_blockfunction contains a "Fallback for other potential keys (Nova, etc.)", but I can't find that in the Converse documentation.This fix rolls back some of these changes in an effort to stay aligned with the Bedrock specifications, as the abstraction of
extract_thinking_from_blockdoes not appear to be needed. Per AWS documentation, content blocks from Converse and content block deltas from ConverseStream are distinct, and as such, keeping them logically distinct in the code seems sensical.llama_index/llama-index-integrations/llms/llama-index-llms-bedrock-converse/llama_index/llms/bedrock_converse/utils.py
Lines 867 to 874 in a771a4f
Also, it adds
thinking_textas part of the tuple returned from_get_content_and_tool_calls, but it isn't used anywhere, as decided by @AstraBert in this comment and then later removed by the author of the PR.One other observation is that the original PR made a change here, which I'm not really sure about (sorry for the formatting in the diff). @logan-markewich , @AstraBert would like your input on the change as I was hesitant to roll it back or adjust.
if text := tool_result_content.get("text", None): - text_content += text - tool_call_ids.append(tool_result_content.get("toolUseId", "")) + # Use first text block as content for compatibility + pass + tool_call_ids.append(tool_result.get("toolUseId", "")) status.append(tool_result.get("status", ""))llama_index/llama-index-integrations/llms/llama-index-llms-bedrock-converse/llama_index/llms/bedrock_converse/base.py
Lines 435 to 438 in a771a4f
Version Bump?
Did I bump the version in the
pyproject.tomlfile of the package I am updating? (Except for thellama-index-corepackage)Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.
Suggested Checklist:
uv run make format; uv run make lintto appease the lint gods