fix: group multiple Bedrock tool results into single user message#4766
Closed
atian8179 wants to merge 1 commit into
Closed
fix: group multiple Bedrock tool results into single user message#4766atian8179 wants to merge 1 commit into
atian8179 wants to merge 1 commit into
Conversation
When an assistant makes multiple tool calls in one turn, each tool result was sent as a separate user message. Bedrock's Converse API requires all tool results for a given assistant turn to be grouped in a single user message, causing a ValidationException. Now consecutive tool messages are detected and their toolResult blocks are appended to the same user message instead of creating new ones. Fixes crewAIInc#4749
Contributor
|
Superseded by #4775, merged 2026-03-10. Closing. |
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.
Problem
When a Bedrock model makes multiple tool calls in a single response, CrewAI sends each tool result as a separate user message:
Bedrock's Converse API requires all tool results for a given assistant message to be grouped in one user message.
Solution
When converting tool messages to Bedrock format, check if the previous converse message is already a user message containing
toolResultblocks. If so, append the newtoolResultto it instead of creating a new message:Fixes #4749
Note
Medium Risk
Moderate risk because it changes how tool responses are serialized into the Bedrock conversation history, which can affect multi-tool-call flows and message alternation edge cases.
Overview
Prevents Bedrock Converse
ValidationExceptionwhen a model returns multiple tool calls in one assistant turn by grouping all correspondingtoolResultblocks into a single subsequentusermessage.Updates
_format_messages_for_converseso consecutivetoolrole messages append theirtoolResultblocks onto the previoususermessage (when it already contains tool results) instead of emitting multiple separateuserturns.Written by Cursor Bugbot for commit d384057. This will update automatically on new commits. Configure here.