From 313a3a4bc61f4e1867064a3628954717a42b1af9 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Thu, 24 Sep 2026 20:42:55 +0100 Subject: [PATCH] Set tool metadata in script (#182713) Co-authored-by: Claude Co-authored-by: Simon Lamon <32477463+silamon@users.noreply.github.com> --- homeassistant/components/script/llm.py | 4 ++++ tests/components/script/test_llm.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/homeassistant/components/script/llm.py b/homeassistant/components/script/llm.py index bd456471cca1..2940ebac2342 100644 --- a/homeassistant/components/script/llm.py +++ b/homeassistant/components/script/llm.py @@ -31,6 +31,10 @@ class ScriptTool(ActionTool): super().__init__(hass, DOMAIN, action) self.name = f"{DOMAIN}__{script_name}" + # The script is named by the user, so its name is already in their + # language. + if state := hass.states.get(script_entity_id): + self.title = state.name if entity_entry and ( aliases := er.async_get_entity_aliases(hass, entity_entry) diff --git a/tests/components/script/test_llm.py b/tests/components/script/test_llm.py index b81b81bdcad3..3fb915df5d67 100644 --- a/tests/components/script/test_llm.py +++ b/tests/components/script/test_llm.py @@ -54,6 +54,14 @@ def _llm_context() -> llm.LLMContext: ) +async def test_script_tool_title(hass: HomeAssistant) -> None: + """Test the script tool is titled with the name the user gave the script.""" + result = await llm_component.async_get_tools(hass, _llm_context(), "assist") + tool = next(tool for tool in result.tools if tool.name == "script__test_script") + assert tool.title == "test script" + assert tool.integration == "script" + + async def test_script_tool_only_exposed(hass: HomeAssistant) -> None: """Test only exposed scripts get a tool.""" result = await llm_component.async_get_tools(hass, _llm_context(), "assist")