Use ToolResult in todo (#182540)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Paulus Schoutsen
2026-09-18 15:24:24 +00:00
committed by GitHub
co-authored by Claude
parent 1ad01fb526
commit 6f9375c905
2 changed files with 10 additions and 9 deletions
+5 -5
View File
@@ -15,8 +15,8 @@ from homeassistant.helpers.llm import (
LLMContext,
Tool,
ToolInput,
ToolResult,
)
from homeassistant.util.json import JsonObjectType
from .const import DOMAIN, TodoServices
from .intent import (
@@ -61,7 +61,7 @@ class TodoGetItemsTool(Tool):
@override
async def async_call(
self, hass: HomeAssistant, tool_input: ToolInput, llm_context: LLMContext
) -> JsonObjectType:
) -> ToolResult:
"""Query a to-do list."""
data = self.parameters(tool_input.tool_args)
result = intent.async_match_targets(
@@ -73,7 +73,7 @@ class TodoGetItemsTool(Tool):
),
)
if not result.is_match:
return {"success": False, "error": "To-do list not found"}
return ToolResult(data={"error": "To-do list not found"}, error=True)
entity_id = result.states[0].entity_id
service_data: dict[str, Any] = {"entity_id": entity_id}
status = data["status"]
@@ -89,9 +89,9 @@ class TodoGetItemsTool(Tool):
return_response=True,
)
if not service_result:
return {"success": False, "error": "To-do list not found"}
return ToolResult(data={"error": "To-do list not found"}, error=True)
items = cast(dict, service_result)[entity_id]["items"]
return {"success": True, "result": items}
return ToolResult(data={"items": items})
@callback
+5 -4
View File
@@ -80,10 +80,11 @@ async def test_todo_get_items_tool(hass: HomeAssistant) -> None:
assert len(calls) == 1
assert calls[0].data == {"entity_id": [ENTITY_ID], "status": ["needs_action"]}
assert result == {
"success": True,
"result": [{"uid": "1234", "status": "needs_action", "summary": "Buy milk"}],
}
assert result == llm.ToolResult(
data={
"items": [{"uid": "1234", "status": "needs_action", "summary": "Buy milk"}]
}
)
@pytest.mark.parametrize(