Files
langchaingo/llms/bedrock/testdata/TestAmazonSingleToolCallWithThinkingConverseAPI.httprr
Dmitry Ng 649d2f5b67 fix: normalize multiple tool calls in Bedrock Converse API
- Refactored message normalization in convertMessages to properly handle all variants of multi-tool-call scenarios
- Introduced aiMessageAccumulator to consolidate consecutive AI messages with text, reasoning, and multiple tool calls into a single assistant message
- Introduced toolResultAccumulator to consolidate consecutive tool result messages into a single user message
- Fixed ValidationException when users structure message chains differently (6 possible variants now supported)
- Added comprehensive test TestConverseAPIMultipleToolCallsVariants covering all 6 user-facing message chain patterns
- Added unit tests for message accumulators and conversion logic to ensure robustness
- Updated existing test recordings to reflect normalized message structure

This ensures the Bedrock Converse API receives properly formatted messages regardless of how users structure their multi-turn conversations with tool calls.
2026-03-15 17:10:04 +03:00

30 lines
4.4 KiB
Plaintext
Generated

httprr trace v1
762 1370
POST https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-sonnet-4-5-20250929-v1%3A0/converse HTTP/1.1
Host: bedrock-runtime.us-east-1.amazonaws.com
User-Agent: langchaingo-httprr
Content-Length: 458
Authorization: AWS4-HMAC-SHA256 test-api-key
Content-Type: application/json
{"additionalModelRequestFields":{"thinking":{"type":"enabled","budget_tokens":2048}},"inferenceConfig":{"maxTokens":4096,"temperature":1},"messages":[{"content":[{"text":"What's the weather in Boston?"}],"role":"user"}],"toolConfig":{"toolChoice":{"auto":{}},"tools":[{"toolSpec":{"description":"Get weather for a location","inputSchema":{"json":{"properties":{"location":{"type":"string"}},"required":["location"],"type":"object"}},"name":"get_weather"}}]}}HTTP/2.0 200 OK
Content-Length: 1204
Content-Type: application/json
Date: Sun, 15 Mar 2026 00:57:50 GMT
X-Amzn-Requestid: 9e53cede-340b-43c7-9135-8fa5fb259fff
{"metrics":{"latencyMs":2113},"output":{"message":{"content":[{"reasoningContent":{"reasoningText":{"signature":"EvMCCkgICxABGAIqQFrvG513/Q3I5NWDC6FH90dAVR1FZrgN4sCzPriQtm4yUC+MCxzSRX2jYG5guNCouTTXXE1ZxNhn8ZB9+aefzoISDM4y2FpNcZUd/5X/fBoMIBO/QGpxTt/9Zqy1IjDCUzrQCzOALkgcKaAjk5hBGf//IhI7Jks1ptB6IQXQwuYaRtoF+4/XrjlP6QOxLWYq2AEV00iUWxj1GEs47qJuzf+r7A59+M1Kq+U1HxDeQ4nIpqtBjhUviGM6MFLOeqgCUILIkMKF6N3IPQQRAS9vACGI1263AgZVdXirDSSkQ4txuAleX8cHCCgEVHFRx0qF29gdH5gd3eQSt/Fk2ZouNSihVwFRPVug8bgiewL+8+StvIg3bwBgojf0dmcBXNlUFzCKdSR3QNlhyycMtR5LBTMopU6PwTrNPT8Dg1aSllvlfEywuODjNLXi90ehFsyYe6ObJAtIj24bvDeYTIdyMIqFtbODzeXTQx4YAQ==","text":"The user is asking about the weather in Boston. I have access to a get_weather function that takes a location parameter. I have all the information I need to make this call - the location is \"Boston\"."}}},{"toolUse":{"input":{"location":"Boston"},"name":"get_weather","toolUseId":"tooluse_b1Bd69QlPENWFN82xVr8kj","type":"tool_use"}}],"role":"assistant"}},"stopReason":"tool_use","usage":{"cacheReadInputTokenCount":0,"cacheReadInputTokens":0,"cacheWriteInputTokenCount":0,"cacheWriteInputTokens":0,"inputTokens":593,"outputTokens":104,"serverToolUsage":{},"totalTokens":697}}1839 549
POST https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-sonnet-4-5-20250929-v1%3A0/converse HTTP/1.1
Host: bedrock-runtime.us-east-1.amazonaws.com
User-Agent: langchaingo-httprr
Content-Length: 1534
Authorization: AWS4-HMAC-SHA256 test-api-key
Content-Type: application/json
{"additionalModelRequestFields":{"thinking":{"type":"enabled","budget_tokens":2048}},"inferenceConfig":{"maxTokens":4096,"temperature":1},"messages":[{"content":[{"text":"What's the weather in Boston?"}],"role":"user"},{"content":[{"reasoningContent":{"reasoningText":{"signature":"EvMCCkgICxABGAIqQFrvG513/Q3I5NWDC6FH90dAVR1FZrgN4sCzPriQtm4yUC+MCxzSRX2jYG5guNCouTTXXE1ZxNhn8ZB9+aefzoISDM4y2FpNcZUd/5X/fBoMIBO/QGpxTt/9Zqy1IjDCUzrQCzOALkgcKaAjk5hBGf//IhI7Jks1ptB6IQXQwuYaRtoF+4/XrjlP6QOxLWYq2AEV00iUWxj1GEs47qJuzf+r7A59+M1Kq+U1HxDeQ4nIpqtBjhUviGM6MFLOeqgCUILIkMKF6N3IPQQRAS9vACGI1263AgZVdXirDSSkQ4txuAleX8cHCCgEVHFRx0qF29gdH5gd3eQSt/Fk2ZouNSihVwFRPVug8bgiewL+8+StvIg3bwBgojf0dmcBXNlUFzCKdSR3QNlhyycMtR5LBTMopU6PwTrNPT8Dg1aSllvlfEywuODjNLXi90ehFsyYe6ObJAtIj24bvDeYTIdyMIqFtbODzeXTQx4YAQ==","text":"The user is asking about the weather in Boston. I have access to a get_weather function that takes a location parameter. I have all the information I need to make this call - the location is \"Boston\"."}}},{"toolUse":{"input":{"location":"Boston"},"name":"get_weather","toolUseId":"tooluse_b1Bd69QlPENWFN82xVr8kj"}}],"role":"assistant"},{"content":[{"toolResult":{"content":[{"text":"{\"temperature\": 72, \"condition\": \"sunny\"}"}],"toolUseId":"tooluse_b1Bd69QlPENWFN82xVr8kj"}}],"role":"user"}],"toolConfig":{"toolChoice":{"auto":{}},"tools":[{"toolSpec":{"description":"Get weather for a location","inputSchema":{"json":{"properties":{"location":{"type":"string"}},"required":["location"],"type":"object"}},"name":"get_weather"}}]}}HTTP/2.0 200 OK
Content-Length: 384
Content-Type: application/json
Date: Sun, 15 Mar 2026 00:57:52 GMT
X-Amzn-Requestid: cab044d8-8730-428b-8fc2-027f153eb6b3
{"metrics":{"latencyMs":1317},"output":{"message":{"content":[{"text":"The weather in Boston is currently sunny with a temperature of 72°F."}],"role":"assistant"}},"stopReason":"end_turn","usage":{"cacheReadInputTokenCount":0,"cacheReadInputTokens":0,"cacheWriteInputTokenCount":0,"cacheWriteInputTokens":0,"inputTokens":721,"outputTokens":19,"serverToolUsage":{},"totalTokens":740}}