semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net: Python: Bedrock connector rejects parallel tool calls (toolResult blocks not merged into one Converse message)

Open kimnamu opened this issue 5 months ago • 2 comments

Describe the bug

Using the Python Bedrock chat completion connector with a model that calls multiple tools in one turn (e.g. Claude Sonnet 4.5), the follow-up Converse request is rejected:

Expected toolResult blocks at messages.X.content for the following Ids: ... but found: ...

Root cause

The function-calling loop (kernel.py invoke_function_call) appends one ChatMessageContent per tool call and one per tool result. BedrockChatCompletion._prepare_chat_history_for_request (connectors/ai/bedrock/services/bedrock_chat_completion.py:173-180) maps each ChatMessageContent 1:1 to a Converse message, so N parallel tool results become N separate role:"user" messages, each with a single toolResult. Converse requires all toolResult blocks for an assistant turn in a single user message (and all toolUse blocks in a single assistant message).

Expected behavior

Chat history with parallel tool calls is usable in follow-up requests without manual merging.

Note

This is the Python counterpart of #13647 (reported for .NET). The sibling Anthropic connector already merges consecutive parallel tool messages (anthropic_chat_completion.py: formatted_messages[-1][content_key] += ...); the Bedrock connector does not. I have a minimal fix + network-free regression test ready and would be happy to open a PR.

Platform

Python, semantic_kernel.connectors.ai.bedrock.

kimnamu avatar Jun 13 '26 14:06 kimnamu

This looks like a useful failed-agent debugging case.

If you can share a sanitized snippet showing what the agent/tool was expected to do, what actually happened, and the trace around the failure, I can run it through Rootlyze and send back a proofpack with likely cause, evidence, next action, prevention guidance, and limitations.

Please remove secrets, API keys, tokens, customer data, and private URLs first.

hermes6941 avatar Jul 09 '26 14:07 hermes6941

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Oct 27 '26 01:10 github-actions[bot]