Skip to content

Python: fix(bedrock): don't send toolChoice when no tools are configured#5172

Open
Bahtya wants to merge 1 commit intomicrosoft:mainfrom
Bahtya:fix/bedrock-toolconfig
Open

Python: fix(bedrock): don't send toolChoice when no tools are configured#5172
Bahtya wants to merge 1 commit intomicrosoft:mainfrom
Bahtya:fix/bedrock-toolconfig

Conversation

@Bahtya
Copy link
Copy Markdown

@Bahtya Bahtya commented Apr 8, 2026

Problem

When using BedrockChatClient with an Agent that has no tools configured, the client still sends toolConfig.toolChoice to the Bedrock API. AWS Bedrock requires toolConfig.tools to be present whenever toolChoice is specified, causing a 400 validation error.

Root Cause

In _prepare_run_options, when tool_choice is set but _prepare_tools returns None (no tools), the code creates an empty dict with tool_config or {} and adds toolChoice to it. This results in sending {"toolChoice": {"auto": {}}} without any tools key.

Fix

Only set toolChoice when tool_config is not None and has a "tools" key. When no tools are configured, toolChoice is silently skipped.

Fixes #5165

BedrockChatClient was sending toolConfig.toolChoice even when no tools
were configured (tools=None). AWS Bedrock requires toolConfig.tools to
be present whenever toolChoice is specified, causing a 400 validation
error.

Only set toolChoice when tool_config has a 'tools' key present.

Fixes microsoft#5165

Signed-off-by: bahtya <bahtyar153@qq.com>
@moonbox3 moonbox3 added the python label Apr 8, 2026
@github-actions github-actions bot changed the title fix(bedrock): don't send toolChoice when no tools are configured Python: fix(bedrock): don't send toolChoice when no tools are configured Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: BedrockChatClient sends toolConfig.toolChoice without toolConfig.tools when agent has no tools

2 participants