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")