generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 606
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
+150
−5
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| """Tests for thinking mode behavior in BedrockModel.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from strands.models.bedrock import BedrockModel | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def model_with_thinking(): | ||
| """Create a BedrockModel with thinking enabled.""" | ||
| return BedrockModel( | ||
| model_id="anthropic.claude-sonnet-4-20250514-v1:0", | ||
| additional_request_fields={"thinking": {"type": "enabled", "budget_tokens": 5000}}, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def model_without_thinking(): | ||
| """Create a BedrockModel without thinking.""" | ||
| return BedrockModel(model_id="anthropic.claude-sonnet-4-20250514-v1:0") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def model_with_thinking_and_other_fields(): | ||
| """Create a BedrockModel with thinking and other additional fields.""" | ||
| return BedrockModel( | ||
| model_id="anthropic.claude-sonnet-4-20250514-v1:0", | ||
| additional_request_fields={ | ||
| "thinking": {"type": "enabled", "budget_tokens": 5000}, | ||
| "some_other_field": "value", | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| def test_thinking_removed_when_forcing_tool_any(model_with_thinking): | ||
| """Thinking should be removed when tool_choice forces tool use with 'any'.""" | ||
| tool_choice = {"any": {}} | ||
| result = model_with_thinking._get_additional_request_fields(tool_choice) | ||
| assert result == {} # thinking removed, no other fields | ||
|
|
||
|
|
||
| def test_thinking_removed_when_forcing_specific_tool(model_with_thinking): | ||
| """Thinking should be removed when tool_choice forces a specific tool.""" | ||
| tool_choice = {"tool": {"name": "structured_output_tool"}} | ||
| result = model_with_thinking._get_additional_request_fields(tool_choice) | ||
| assert result == {} # thinking removed, no other fields | ||
|
|
||
|
|
||
| def test_thinking_preserved_with_auto_tool_choice(model_with_thinking): | ||
| """Thinking should be preserved when tool_choice is 'auto'.""" | ||
| tool_choice = {"auto": {}} | ||
| result = model_with_thinking._get_additional_request_fields(tool_choice) | ||
| assert result == {"additionalModelRequestFields": {"thinking": {"type": "enabled", "budget_tokens": 5000}}} | ||
|
|
||
|
|
||
| def test_thinking_preserved_with_none_tool_choice(model_with_thinking): | ||
| """Thinking should be preserved when tool_choice is None.""" | ||
| result = model_with_thinking._get_additional_request_fields(None) | ||
| assert result == {"additionalModelRequestFields": {"thinking": {"type": "enabled", "budget_tokens": 5000}}} | ||
|
|
||
|
|
||
| def test_other_fields_preserved_when_thinking_removed(model_with_thinking_and_other_fields): | ||
| """Other additional fields should be preserved when thinking is removed.""" | ||
| tool_choice = {"any": {}} | ||
| result = model_with_thinking_and_other_fields._get_additional_request_fields(tool_choice) | ||
| assert result == {"additionalModelRequestFields": {"some_other_field": "value"}} | ||
|
|
||
|
|
||
| def test_no_fields_when_model_has_no_additional_fields(model_without_thinking): | ||
| """Should return empty dict when model has no additional_request_fields.""" | ||
| tool_choice = {"any": {}} | ||
| result = model_without_thinking._get_additional_request_fields(tool_choice) | ||
| assert result == {} | ||
|
|
||
|
|
||
| def test_fields_preserved_when_no_thinking_and_forcing_tool(): | ||
| """Additional fields without thinking should be preserved when forcing tool.""" | ||
| model = BedrockModel( | ||
| model_id="anthropic.claude-sonnet-4-20250514-v1:0", | ||
| additional_request_fields={"some_field": "value"}, | ||
| ) | ||
| tool_choice = {"any": {}} | ||
| result = model._get_additional_request_fields(tool_choice) | ||
| assert result == {"additionalModelRequestFields": {"some_field": "value"}} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.