generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 605
fix(bedrock): disable thinking mode when forcing tool_choice #1495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dbschmigelski
merged 3 commits into
strands-agents:main
from
strands-agent:fix/thinking-structured-output-v2
Jan 16, 2026
Merged
fix(bedrock): disable thinking mode when forcing tool_choice #1495
dbschmigelski
merged 3 commits into
strands-agents:main
from
strands-agent:fix/thinking-structured-output-v2
Jan 16, 2026
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Fixes strands-agents#1485 - Cannot use structured_output with thinking enabled. When BedrockModel has thinking mode enabled via additional_request_fields, and the event loop forces tool_choice (for structured_output retry), Bedrock's API returns an error because thinking is not allowed with forced tool use. This PR adds a helper method _get_additional_request_fields() that temporarily removes the thinking configuration when tool_choice is forcing tool use (not 'auto' and not None), while preserving all other additional request fields. - Adds _get_additional_request_fields() helper method - Preserves thinking for normal interactions (auto/None tool_choice) - Removes thinking only when forcing tool use - Preserves other additional_request_fields when thinking is removed - Adds comprehensive unit tests for all scenarios
4062cde to
93dabb9
Compare
3 tasks
dbschmigelski
previously approved these changes
Jan 15, 2026
mkmeral
previously approved these changes
Jan 15, 2026
afarntrog
reviewed
Jan 15, 2026
afarntrog
approved these changes
Jan 15, 2026
mkmeral
approved these changes
Jan 16, 2026
7 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1485 - Cannot use structured_output with thinking enabled.
Supersedes #1490 (cleaner implementation rebased on latest main after #1336 pyupgrade merge)
Problem
When using BedrockModel with thinking mode enabled via
additional_request_fields, if structured_output fails to generate a tool call on the first attempt, the event loop forcestool_choice(set to{"any": {}}) to retry. However, Bedrock's API doesn't allow thinking mode to be enabled whentool_choiceforces tool use, resulting in:Solution
Adds a helper method
_get_additional_request_fields()that temporarily removes thethinkingconfiguration fromadditionalModelRequestFieldswhentool_choiceis forcing tool use (i.e., not{"auto": {}}).Key changes:
tool_choiceis forcing a tool (notautoand notNone)additional_request_fieldswithout thethinkingkey when forcingautoorNone)additional_request_fieldswhen removing thinkingTesting
Added 7 comprehensive unit tests in
test_bedrock_thinking.pycovering:{"any": {}}){"tool": {...}}){"auto": {}})Behavior
Before: Agent crashes with ValidationException when structured_output + thinking enabled
After: Agent gracefully retries structured_output by temporarily disabling thinking for that specific retry
Related Issues
Fixes #1485
Supersedes #1490
Type of Change
Testing
hatch test tests/strands/models/test_bedrock_thinking.py- 7 passedhatch test tests/strands/models/test_bedrock.py- 94 passedhatch fmt --linter- All checks passedChecklist