mirror of
https://github.com/home-assistant/core.git
synced 2026-08-03 20:24:55 +02:00
Add assist_satellite LLM tools platform (#175655)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Michael Hansen <mike@rhasspy.org>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""LLM tools for the assist_satellite integration."""
|
||||
|
||||
from homeassistant.components.llm import LLMTools
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import intent
|
||||
from homeassistant.helpers.llm import LLM_API_ASSIST, IntentTool, LLMContext, Tool
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_tools(
|
||||
hass: HomeAssistant, llm_context: LLMContext, api_id: str
|
||||
) -> LLMTools | None:
|
||||
"""Return the broadcast LLM tool."""
|
||||
if api_id != LLM_API_ASSIST:
|
||||
return None
|
||||
|
||||
# assist_satellite registers the broadcast intent when it is set up, and
|
||||
# this platform is only queried once that has happened.
|
||||
tools: list[Tool] = [
|
||||
IntentTool(handler.intent_type, handler)
|
||||
for handler in intent.async_get(hass)
|
||||
if handler.intent_type == intent.INTENT_BROADCAST
|
||||
]
|
||||
return LLMTools(tools=tools)
|
||||
@@ -0,0 +1,34 @@
|
||||
"""Tests for the assist_satellite LLM tools platform."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import llm as llm_component
|
||||
from homeassistant.core import Context, HomeAssistant
|
||||
from homeassistant.helpers import llm
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
async def init_integrations(hass: HomeAssistant) -> None:
|
||||
"""Set up the integrations; assist_satellite registers the broadcast intent."""
|
||||
assert await async_setup_component(hass, "homeassistant", {})
|
||||
assert await async_setup_component(hass, "intent", {})
|
||||
assert await async_setup_component(hass, "llm", {})
|
||||
assert await async_setup_component(hass, "assist_satellite", {})
|
||||
|
||||
|
||||
def _llm_context() -> llm.LLMContext:
|
||||
"""Return an LLM context for the conversation assistant."""
|
||||
return llm.LLMContext(
|
||||
platform="test_platform",
|
||||
context=Context(),
|
||||
language="*",
|
||||
assistant="conversation",
|
||||
device_id=None,
|
||||
)
|
||||
|
||||
|
||||
async def test_broadcast_tool_offered(hass: HomeAssistant) -> None:
|
||||
"""Test the broadcast intent is exposed as an LLM tool."""
|
||||
result = await llm_component.async_get_tools(hass, _llm_context(), "assist")
|
||||
assert "HassBroadcast" in [tool.name for tool in result.tools]
|
||||
Reference in New Issue
Block a user