fix(anthropic): treat adaptive thinking as enabled when mapping response_format

is_thinking_enabled only recognised thinking.type=enabled, so a request that
paired thinking.type=adaptive with response_format took the synthetic JSON
tool path with a forced tool_choice, which Anthropic rejects alongside
thinking. The same check also gates the Bedrock Converse and Databricks
forced tool_choice downgrades, so they now see adaptive thinking too.
This commit is contained in:
ryan-crabbe-berri 2026-10-13 19:01:59 -07:00
parent 596c51a5fa
commit ad9e861ae7
3 changed files with 31 additions and 1 deletions

View file

@ -124,7 +124,11 @@ class BaseConfig(ABC):
def is_thinking_enabled(self, non_default_params: dict) -> bool:
thinking: Final = non_default_params.get("thinking")
thinking_type: Final = thinking.get("type") if isinstance(thinking, dict) else None
return thinking is True or thinking_type == "enabled" or non_default_params.get("reasoning_effort") is not None
return (
thinking is True
or thinking_type in ("enabled", "adaptive")
or non_default_params.get("reasoning_effort") is not None
)
def is_max_tokens_in_request(self, non_default_params: dict) -> bool:
"""

View file

@ -760,6 +760,31 @@ def test_bedrock_chat_invoke_tool_based_response_format_still_upgrades_legacy_th
assert result["output_config"] == {"effort": "high"}
def test_bedrock_chat_invoke_adaptive_thinking_with_tool_based_response_format_avoids_forced_tool_choice(
local_model_cost_map,
):
result = AmazonAnthropicClaudeConfig().map_openai_params(
non_default_params={
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "test_schema",
"schema": {"type": "object", "properties": {"result": {"type": "string"}}},
},
},
"thinking": {"type": "adaptive"},
"max_tokens": 8192,
},
optional_params={},
model="us.anthropic.claude-opus-5",
drop_params=False,
)
assert "tools" in result
assert "tool_choice" not in result
assert result["thinking"] == {"type": "adaptive"}
def test_bedrock_chat_invoke_response_format_stub_still_upgrades_legacy_thinking(local_model_cost_map):
"""Regression: the tool-based ``response_format`` path swaps in a Claude 3 stub
model before the shared Anthropic mapping, which hid the adaptive-only model

View file

@ -50,6 +50,7 @@ class TestIsThinkingEnabled:
({"thinking": None}, False),
# thinking={'type': 'enabled'} returns True
({"thinking": {"type": "enabled"}}, True),
({"thinking": {"type": "adaptive"}}, True),
# thinking key missing returns False
({}, False),
# thinking={} returns False