Description:
When using AmazonBedrockChatGenerator with a model capable of requesting multiple tool calls in a single turn (like Anthropic Claude 3.5 Sonnet), the component fails when attempting to send the results of these multiple tool executions back to the Bedrock API.
Steps Observed:
- The Haystack Agent calls
AmazonBedrockChatGenerator.
- The Bedrock model (
anthropic.claude-3-5-sonnet-20240620-v1:0) responds with a message containing multiple distinct tool_calls requests, each with a unique ID. For example:
- Call 1:
{ "id": "tooluse_TIB5o2PCQHW_fpWTOwvROA", "function": { "name": "get_weather_forecast", ... } }
- Call 2:
{ "id": "tooluse_45K4_G22SEaolJj1FAD14w", "function": { "name": "qdrant-find", ... } }
- The
ToolInvoker (within the Agent) successfully receives these requests and executes the corresponding tools (get_weather_forecast and qdrant-find).
AmazonBedrockChatGenerator attempts to continue the conversation by sending the results of both tool executions back to the Bedrock ConverseStream API.
- The call to
client.converse_stream fails with a botocore.errorfactory.ValidationException.
Error Message:
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ConverseStream operation: Expected toolResult blocks at messages.4.content for the following Ids: tooluse_45K4_G22SEaolJj1FAD14w, but found: tooluse_TIB5o2PCQHW_fpWTOwvROA
Analysis:
The error message clearly indicates that the Bedrock API was expecting the result associated with the qdrant-find tool call (tooluse_45K4_G22SEaolJj1FAD14w) but instead received the result associated with the get_weather_forecast tool call (tooluse_TIB5o2PCQHW_fpWTOwvROA) at that position in the message list (messages.4.content).
It seems that when AmazonBedrockChatGenerator prepares the message containing the tool results to send back to Bedrock, it is incorrectly ordering or formatting the toolResult blocks when multiple results need to be sent simultaneously. The Bedrock API requires the results to be provided and correctly matched to their corresponding toolUseId from the previous turn.
Note: Single tool calls function correctly, isolating the issue specifically to the handling of multiple concurrent tool call results.
Expected Behavior:
AmazonBedrockChatGenerator should correctly format the message sent back to the Bedrock ConverseStream API, including all toolResult blocks, correctly ordered and matched to their respective toolUseIds from the LLM's previous turn, allowing the conversation flow to continue after multiple tool executions.
Actual Behavior:
A ValidationException is raised by botocore/Bedrock, preventing the agent from processing the results of the multiple tool calls and halting execution with a PipelineRuntimeError.
Environment:
- Haystack Version: 2.13
- Haystack Amazon Bedrock Integration Version: 3.5.1
- Model:
anthropic.claude-3-5-sonnet-20240620-v1:0 (via Bedrock ConverseStream API)
- Python Version: 3.10
Steps to reproduce:
Description:
When using
AmazonBedrockChatGeneratorwith a model capable of requesting multiple tool calls in a single turn (like Anthropic Claude 3.5 Sonnet), the component fails when attempting to send the results of these multiple tool executions back to the Bedrock API.Steps Observed:
AmazonBedrockChatGenerator.anthropic.claude-3-5-sonnet-20240620-v1:0) responds with a message containing multiple distincttool_callsrequests, each with a unique ID. For example:{ "id": "tooluse_TIB5o2PCQHW_fpWTOwvROA", "function": { "name": "get_weather_forecast", ... } }{ "id": "tooluse_45K4_G22SEaolJj1FAD14w", "function": { "name": "qdrant-find", ... } }ToolInvoker(within the Agent) successfully receives these requests and executes the corresponding tools (get_weather_forecastandqdrant-find).AmazonBedrockChatGeneratorattempts to continue the conversation by sending the results of both tool executions back to the BedrockConverseStreamAPI.client.converse_streamfails with abotocore.errorfactory.ValidationException.Error Message:
Analysis:
The error message clearly indicates that the Bedrock API was expecting the result associated with the
qdrant-findtool call (tooluse_45K4_G22SEaolJj1FAD14w) but instead received the result associated with theget_weather_forecasttool call (tooluse_TIB5o2PCQHW_fpWTOwvROA) at that position in the message list (messages.4.content).It seems that when
AmazonBedrockChatGeneratorprepares the message containing the tool results to send back to Bedrock, it is incorrectly ordering or formatting thetoolResultblocks when multiple results need to be sent simultaneously. The Bedrock API requires the results to be provided and correctly matched to their correspondingtoolUseIdfrom the previous turn.Note: Single tool calls function correctly, isolating the issue specifically to the handling of multiple concurrent tool call results.
Expected Behavior:
AmazonBedrockChatGeneratorshould correctly format the message sent back to the BedrockConverseStreamAPI, including alltoolResultblocks, correctly ordered and matched to their respectivetoolUseIds from the LLM's previous turn, allowing the conversation flow to continue after multiple tool executions.Actual Behavior:
A
ValidationExceptionis raised by botocore/Bedrock, preventing the agent from processing the results of the multiple tool calls and halting execution with aPipelineRuntimeError.Environment:
anthropic.claude-3-5-sonnet-20240620-v1:0(via BedrockConverseStreamAPI)Steps to reproduce:
AmazonBedrockChatGeneratorand update the prompt to force multiple tool calls