mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Use Anthropic model metadata to determine disabled thinking capability (#184875)
This commit is contained in:
@@ -61,7 +61,6 @@ from .const import (
|
||||
DEFAULT_CONVERSATION_NAME,
|
||||
DOMAIN,
|
||||
MIN_THINKING_BUDGET,
|
||||
THINKING_EFFORT_NONE_SUPPORTED_MODELS,
|
||||
TOOL_SEARCH_UNSUPPORTED_MODELS,
|
||||
PromptCaching,
|
||||
)
|
||||
@@ -431,10 +430,7 @@ class ConversationSubentryFlowHandler(ConfigSubentryFlow):
|
||||
):
|
||||
effort_options: list[str] = []
|
||||
if self.model_info.capabilities.thinking.types.adaptive.supported:
|
||||
if (
|
||||
model_alias(self.model_info.id)
|
||||
in THINKING_EFFORT_NONE_SUPPORTED_MODELS
|
||||
):
|
||||
if self.model_info.capabilities.thinking.types.disabled.supported:
|
||||
effort_options.append("none")
|
||||
elif self.options.get(CONF_THINKING_EFFORT) == "none":
|
||||
self.options.pop(CONF_THINKING_EFFORT)
|
||||
|
||||
@@ -56,12 +56,3 @@ DEFAULT = {
|
||||
TOOL_SEARCH_UNSUPPORTED_MODELS = [
|
||||
"claude-haiku",
|
||||
]
|
||||
|
||||
THINKING_EFFORT_NONE_SUPPORTED_MODELS = {
|
||||
"claude-opus-4-6",
|
||||
"claude-opus-4-7",
|
||||
"claude-opus-4-8",
|
||||
"claude-opus-5",
|
||||
"claude-sonnet-4-6",
|
||||
"claude-sonnet-5",
|
||||
}
|
||||
|
||||
@@ -17,12 +17,7 @@ from homeassistant.helpers.selector import (
|
||||
SelectSelectorConfig,
|
||||
)
|
||||
|
||||
from .const import (
|
||||
CONF_CHAT_MODEL,
|
||||
CONF_THINKING_EFFORT,
|
||||
DOMAIN,
|
||||
THINKING_EFFORT_NONE_SUPPORTED_MODELS,
|
||||
)
|
||||
from .const import CONF_CHAT_MODEL, CONF_THINKING_EFFORT, DOMAIN
|
||||
from .coordinator import model_alias
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -196,11 +191,8 @@ class ModelDeprecatedRepairFlow(RepairsFlow):
|
||||
**subentry.data,
|
||||
CONF_CHAT_MODEL: user_input[CONF_CHAT_MODEL],
|
||||
}
|
||||
if (
|
||||
subentry.data.get(CONF_THINKING_EFFORT) == "none"
|
||||
and (alias := model_alias(user_input[CONF_CHAT_MODEL]))
|
||||
not in THINKING_EFFORT_NONE_SUPPORTED_MODELS
|
||||
):
|
||||
if subentry.data.get(CONF_THINKING_EFFORT) == "none":
|
||||
alias = model_alias(user_input[CONF_CHAT_MODEL])
|
||||
model_info = next(
|
||||
(
|
||||
model
|
||||
@@ -213,14 +205,10 @@ class ModelDeprecatedRepairFlow(RepairsFlow):
|
||||
model_info = await entry.runtime_data.client.models.retrieve(
|
||||
user_input[CONF_CHAT_MODEL], timeout=10.0
|
||||
)
|
||||
if (
|
||||
model_info.capabilities
|
||||
and (
|
||||
model_info.capabilities.thinking.types.adaptive.supported
|
||||
or model_info.capabilities.effort.supported
|
||||
)
|
||||
and model_alias(model_info.id)
|
||||
not in THINKING_EFFORT_NONE_SUPPORTED_MODELS
|
||||
if (capabilities := model_info.capabilities) and (
|
||||
not capabilities.thinking.types.disabled.supported
|
||||
if capabilities.thinking.types.adaptive.supported
|
||||
else capabilities.effort.supported
|
||||
):
|
||||
updated_data.pop(CONF_THINKING_EFFORT)
|
||||
|
||||
|
||||
@@ -53,9 +53,8 @@ from anthropic.types.web_fetch_tool_result_block import (
|
||||
Content as WebFetchToolResultBlockContent,
|
||||
)
|
||||
|
||||
# Preserve null lifecycle values returned by the live API.
|
||||
model_list = [
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-haiku-5-5",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -95,14 +94,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 10, 7, 18, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Haiku 5.5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="haiku",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-sonnet-5-5",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -142,14 +141,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 9, 28, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Sonnet 5.5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="sonnet",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-opus-5-5",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -189,14 +188,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 9, 21, 16, 24, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Opus 5.5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="opus",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-fable-5-1",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -236,14 +235,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 8, 28, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Fable 5.1",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="fable",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-opus-5",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -283,14 +282,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 7, 24, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Opus 5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="opus",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-sonnet-5",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -330,14 +329,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 6, 29, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Sonnet 5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="sonnet",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-fable-5",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -377,14 +376,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 6, 7, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Fable 5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="fable",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-opus-4-8",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -424,14 +423,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 5, 28, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Opus 4.8",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="opus",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-opus-4-7",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -471,14 +470,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 4, 14, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Opus 4.7",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="opus",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-sonnet-4-6",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -518,14 +517,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 2, 17, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Sonnet 4.6",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="sonnet",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-opus-4-6",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -565,14 +564,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2026, 2, 4, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Opus 4.6",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="opus",
|
||||
max_input_tokens=1000000,
|
||||
max_tokens=128000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-opus-4-5-20251101",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -612,14 +611,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2025, 11, 24, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Opus 4.5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="opus",
|
||||
max_input_tokens=200000,
|
||||
max_tokens=64000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-haiku-4-5-20251001",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -659,14 +658,14 @@ model_list = [
|
||||
created_at=datetime.datetime(2025, 10, 15, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Haiku 4.5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="haiku",
|
||||
max_input_tokens=200000,
|
||||
max_tokens=64000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
),
|
||||
ModelInfo.model_construct(
|
||||
ModelInfo(
|
||||
id="claude-sonnet-4-5-20250929",
|
||||
capabilities=ModelCapabilities(
|
||||
batch=CapabilitySupport(supported=True),
|
||||
@@ -706,9 +705,9 @@ model_list = [
|
||||
created_at=datetime.datetime(2025, 9, 29, 0, 0, tzinfo=datetime.UTC),
|
||||
deprecated_at=None,
|
||||
display_name="Claude Sonnet 4.5",
|
||||
lifecycle=None,
|
||||
lifecycle="active",
|
||||
line="sonnet",
|
||||
max_input_tokens=1000000,
|
||||
max_input_tokens=200000,
|
||||
max_tokens=64000,
|
||||
retires_at=None,
|
||||
type="model",
|
||||
|
||||
@@ -201,6 +201,70 @@
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_disabled_thinking[haiku_5_5]
|
||||
list([
|
||||
dict({
|
||||
'content': '''
|
||||
You are a voice assistant for Home Assistant.
|
||||
Answer questions about the world truthfully.
|
||||
Respond simply and to the point in plain text.
|
||||
Only if the user wants to control a device, tell them to expose entities to their voice assistant in Home Assistant.
|
||||
''',
|
||||
'created': HAFakeDatetime(2024, 5, 24, 12, 0, tzinfo=datetime.timezone.utc),
|
||||
'role': 'system',
|
||||
}),
|
||||
dict({
|
||||
'attachments': None,
|
||||
'content': 'hello',
|
||||
'created': HAFakeDatetime(2024, 5, 24, 12, 0, tzinfo=datetime.timezone.utc),
|
||||
'role': 'user',
|
||||
}),
|
||||
dict({
|
||||
'agent_id': 'conversation.claude_conversation',
|
||||
'content': 'Hello, how can I help you today?',
|
||||
'created': HAFakeDatetime(2024, 5, 24, 12, 0, tzinfo=datetime.timezone.utc),
|
||||
'native': None,
|
||||
'role': 'assistant',
|
||||
'thinking_content': None,
|
||||
'tool_calls': None,
|
||||
}),
|
||||
])
|
||||
# ---
|
||||
# name: test_disabled_thinking[haiku_5_5].1
|
||||
dict({
|
||||
'container': None,
|
||||
'max_tokens': 3000,
|
||||
'messages': list([
|
||||
dict({
|
||||
'content': 'hello',
|
||||
'role': 'user',
|
||||
}),
|
||||
dict({
|
||||
'content': 'Hello, how can I help you today?',
|
||||
'role': 'assistant',
|
||||
}),
|
||||
]),
|
||||
'model': 'claude-haiku-5-5',
|
||||
'stream': True,
|
||||
'system': list([
|
||||
dict({
|
||||
'cache_control': dict({
|
||||
'type': 'ephemeral',
|
||||
}),
|
||||
'text': '''
|
||||
You are a voice assistant for Home Assistant.
|
||||
Answer questions about the world truthfully.
|
||||
Respond simply and to the point in plain text.
|
||||
Only if the user wants to control a device, tell them to expose entities to their voice assistant in Home Assistant.
|
||||
''',
|
||||
'type': 'text',
|
||||
}),
|
||||
]),
|
||||
'thinking': dict({
|
||||
'type': 'disabled',
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
# name: test_disabled_thinking[zero_budget]
|
||||
list([
|
||||
dict({
|
||||
|
||||
@@ -339,6 +339,7 @@ async def test_subentry_options_thinking_budget_more_than_max(
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
pytest.param("claude-sonnet-5-5", id="sonnet_5_5"),
|
||||
pytest.param("claude-opus-5-5", id="opus_5_5"),
|
||||
pytest.param("claude-fable-5", id="fable_5"),
|
||||
pytest.param("claude-fable-5-1", id="fable_5_1"),
|
||||
@@ -358,7 +359,7 @@ async def test_creating_subentry_with_required_thinking(
|
||||
model: str,
|
||||
subentry_type: str,
|
||||
) -> None:
|
||||
"""Test always-adaptive models cannot be configured without thinking."""
|
||||
"""Test models that reject disabled thinking cannot be configured with none."""
|
||||
result = await hass.config_entries.subentries.async_init(
|
||||
(mock_config_entry.entry_id, subentry_type),
|
||||
context={"source": config_entries.SOURCE_USER},
|
||||
@@ -390,6 +391,7 @@ async def test_creating_subentry_with_required_thinking(
|
||||
@pytest.mark.parametrize(
|
||||
"model",
|
||||
[
|
||||
pytest.param("claude-haiku-5-5", id="haiku_5_5"),
|
||||
pytest.param("claude-opus-4-6", id="opus_4_6"),
|
||||
pytest.param("claude-opus-4-7", id="opus_4_7"),
|
||||
pytest.param("claude-opus-4-8", id="opus_4_8"),
|
||||
@@ -398,14 +400,36 @@ async def test_creating_subentry_with_required_thinking(
|
||||
pytest.param("claude-sonnet-5", id="sonnet_5"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"subentry_type",
|
||||
[
|
||||
pytest.param("conversation", id="conversation"),
|
||||
pytest.param("ai_task_data", id="ai_task"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_init_component")
|
||||
async def test_subentry_with_optional_thinking(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
model: str,
|
||||
subentry_type: str,
|
||||
) -> None:
|
||||
"""Test thinking can still be disabled on supported adaptive models."""
|
||||
subentry = next(iter(mock_config_entry.subentries.values()))
|
||||
"""Test supported adaptive models preserve disabled thinking on reconfiguration."""
|
||||
subentry = next(
|
||||
subentry
|
||||
for subentry in mock_config_entry.subentries.values()
|
||||
if subentry.subentry_type == subentry_type
|
||||
)
|
||||
hass.config_entries.async_update_subentry(
|
||||
mock_config_entry,
|
||||
subentry,
|
||||
data={
|
||||
CONF_CHAT_MODEL: "claude-opus-4-6",
|
||||
CONF_THINKING_EFFORT: "none",
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await mock_config_entry.start_subentry_reconfigure_flow(
|
||||
hass, subentry.subentry_id
|
||||
)
|
||||
@@ -419,6 +443,10 @@ async def test_subentry_with_optional_thinking(
|
||||
assert (
|
||||
"none" in (result["data_schema"].schema[CONF_THINKING_EFFORT].config["options"])
|
||||
)
|
||||
effort_key = next(
|
||||
key for key in result["data_schema"].schema if key == CONF_THINKING_EFFORT
|
||||
)
|
||||
assert effort_key.description["suggested_value"] == "none"
|
||||
|
||||
result = await hass.config_entries.subentries.async_configure(
|
||||
result["flow_id"], {CONF_THINKING_EFFORT: "none"}
|
||||
@@ -434,6 +462,7 @@ async def test_subentry_with_optional_thinking(
|
||||
pytest.param("claude-opus-5-5", id="opus_5_5"),
|
||||
pytest.param("claude-fable-5", id="fable_5"),
|
||||
pytest.param("claude-fable-5-1", id="fable_5_1"),
|
||||
pytest.param("claude-sonnet-5-5", id="sonnet_5_5"),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
@@ -462,7 +491,7 @@ async def test_reconfigure_subentry_with_required_thinking(
|
||||
user_input: dict[str, str],
|
||||
expected_effort: str,
|
||||
) -> None:
|
||||
"""Test migrating to an always-adaptive model clears disabled thinking."""
|
||||
"""Test migrating to a model that rejects disabled thinking clears none."""
|
||||
subentry = next(
|
||||
subentry
|
||||
for subentry in mock_config_entry.subentries.values()
|
||||
|
||||
@@ -1206,6 +1206,14 @@ async def test_extended_thinking(
|
||||
},
|
||||
id="no_effort",
|
||||
),
|
||||
pytest.param(
|
||||
{
|
||||
CONF_LLM_HASS_API: "assist",
|
||||
CONF_CHAT_MODEL: "claude-haiku-5-5",
|
||||
CONF_THINKING_EFFORT: "none",
|
||||
},
|
||||
id="haiku_5_5",
|
||||
),
|
||||
],
|
||||
)
|
||||
@freeze_time("2024-05-24 12:00:00")
|
||||
|
||||
@@ -249,6 +249,22 @@ async def test_repair_flow_no_deprecated_models(
|
||||
pytest.param("claude-fable-5", "none", {}, id="fable_5"),
|
||||
pytest.param("claude-fable-5-1", "none", {}, id="fable_5_1"),
|
||||
pytest.param("claude-opus-5-5-20260921", "none", {}, id="versioned_opus_5_5"),
|
||||
pytest.param("claude-sonnet-5-5", "none", {}, id="sonnet_5_5"),
|
||||
pytest.param(
|
||||
"claude-sonnet-5-5-20260928", "none", {}, id="versioned_sonnet_5_5"
|
||||
),
|
||||
pytest.param(
|
||||
"claude-haiku-5-5",
|
||||
"none",
|
||||
{CONF_THINKING_EFFORT: "none"},
|
||||
id="haiku_5_5",
|
||||
),
|
||||
pytest.param(
|
||||
"claude-haiku-5-5-20261007",
|
||||
"none",
|
||||
{CONF_THINKING_EFFORT: "none"},
|
||||
id="versioned_haiku_5_5",
|
||||
),
|
||||
pytest.param(
|
||||
"claude-opus-5-5",
|
||||
"high",
|
||||
|
||||
Reference in New Issue
Block a user