Skip to content

fix: group multiple Bedrock tool results into single user message#4766

Closed
atian8179 wants to merge 1 commit into
crewAIInc:mainfrom
atian8179:fix/bedrock-tool-result-grouping
Closed

fix: group multiple Bedrock tool results into single user message#4766
atian8179 wants to merge 1 commit into
crewAIInc:mainfrom
atian8179:fix/bedrock-tool-result-grouping

Conversation

@atian8179
Copy link
Copy Markdown

@atian8179 atian8179 commented Mar 8, 2026

Problem

When a Bedrock model makes multiple tool calls in a single response, CrewAI sends each tool result as a separate user message:

Message 0: user (prompt)
Message 1: assistant (toolUse A, toolUse B)
Message 2: user (toolResult A)  ← Separate message
Message 3: user (toolResult B)  ← Separate message — causes ValidationException

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 toolResult blocks. If so, append the new toolResult to it instead of creating a new message:

Message 0: user (prompt)
Message 1: assistant (toolUse A, toolUse B)
Message 2: user (toolResult A, toolResult B)  ← Grouped correctly

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 ValidationException when a model returns multiple tool calls in one assistant turn by grouping all corresponding toolResult blocks into a single subsequent user message.

Updates _format_messages_for_converse so consecutive tool role messages append their toolResult blocks onto the previous user message (when it already contains tool results) instead of emitting multiple separate user turns.

Written by Cursor Bugbot for commit d384057. This will update automatically on new commits. Configure here.

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
@greysonlalonde
Copy link
Copy Markdown
Contributor

Superseded by #4775, merged 2026-03-10. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] AWS Bedrock ValidationException with multiple tool calls - toolResult blocks not grouped

2 participants