Filter Anthropic schema (#168542)

This commit is contained in:
Denis Shulyaka
2026-04-21 09:55:00 -04:00
committed by GitHub
parent 5a487d452d
commit 7c7c075df4
2 changed files with 31 additions and 10 deletions
+5 -1
View File
@@ -124,10 +124,14 @@ def _format_tool(
tool: llm.Tool, custom_serializer: Callable[[Any], Any] | None
) -> ToolParam:
"""Format tool specification."""
unsupported_keys = {"oneOf", "anyOf", "allOf"}
schema = convert(tool.parameters, custom_serializer=custom_serializer)
schema = {k: v for k, v in schema.items() if k not in unsupported_keys}
return ToolParam(
name=tool.name,
description=tool.description or "",
input_schema=convert(tool.parameters, custom_serializer=custom_serializer),
input_schema=schema,
)
@@ -49,6 +49,8 @@ from homeassistant.components.anthropic.const import (
DOMAIN,
)
from homeassistant.components.anthropic.entity import CitationDetails, ContentDetails
from homeassistant.components.homeassistant.exposed_entities import async_expose_entity
from homeassistant.components.intent import async_register_timer_handler
from homeassistant.const import CONF_LLM_HASS_API
from homeassistant.core import Context, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
@@ -486,19 +488,25 @@ async def test_assist_api_tools_conversion(
) -> None:
"""Test that we are able to convert actual tools from Assist API."""
for component in (
"intent",
"todo",
"light",
"shopping_list",
"humidifier",
"calendar",
"climate",
"media_player",
"vacuum",
"cover",
"weather",
"demo",
"humidifier",
"intent",
"light",
"media_player",
"script",
"shopping_list",
"todo",
"vacuum",
"weather",
):
assert await async_setup_component(hass, component, {})
hass.states.async_set(f"{component}.test", "on")
async_expose_entity(hass, "conversation", f"{component}.test", True)
async_register_timer_handler(hass, "test_device", lambda *args: None)
agent_id = "conversation.claude_conversation"
@@ -506,11 +514,20 @@ async def test_assist_api_tools_conversion(
create_content_block(0, ["Hello, how can I help you?"])
]
await conversation.async_converse(hass, "hello", None, Context(), agent_id=agent_id)
await conversation.async_converse(
hass, "hello", None, Context(), agent_id=agent_id, device_id="test_device"
)
tools = mock_create_stream.mock_calls[0][2]["tools"]
assert tools
for tool in tools:
for key in ("oneOf", "allOf", "anyOf"):
assert key not in tool["input_schema"], (
f"{tool['name']}.input_schema: input_schema does not support "
"oneOf, allOf, or anyOf at the top level"
)
async def test_unknown_hass_api(
hass: HomeAssistant,