feat(anthropic): support adaptive thinking mode (#36293)

Thank you!
This commit is contained in:
vladpostoaca-stripe
2026-03-29 02:53:55 +02:00
committed by GitHub
parent 4d9842da67
commit fe2f105ce7
2 changed files with 67 additions and 3 deletions

View File

@@ -1652,7 +1652,7 @@ class ChatAnthropic(BaseChatModel):
# _get_llm_for_structured_output_when_thinking_is_enabled.
if (
self.thinking is not None
and self.thinking.get("type") == "enabled"
and self.thinking.get("type") in ("enabled", "adaptive")
and "tool_choice" in kwargs
and kwargs["tool_choice"].get("type") in ("any", "tool")
):
@@ -1781,7 +1781,10 @@ class ChatAnthropic(BaseChatModel):
# The result of convert_to_anthropic_tool for 'method=function_calling' will
# always be an AnthropicTool
tool_name = formatted_tool["name"]
if self.thinking is not None and self.thinking.get("type") == "enabled":
if self.thinking is not None and self.thinking.get("type") in (
"enabled",
"adaptive",
):
llm = self._get_llm_for_structured_output_when_thinking_is_enabled(
schema,
formatted_tool,
@@ -1993,7 +1996,7 @@ def _tools_in_params(params: dict) -> bool:
def _thinking_in_params(params: dict) -> bool:
return params.get("thinking", {}).get("type") == "enabled"
return params.get("thinking", {}).get("type") in ("enabled", "adaptive")
def _documents_in_params(params: dict) -> bool: