Skip to content

Commit 51b9dca

Browse files
authored
fix: clarify ha_search_entities vs ha_deep_search descriptions to prevent tool misuse (#761)
LLM agents were defaulting to ha_deep_search for simple entity lookups by name because its description sounded more comprehensive. Updated both docstrings to make the distinction explicit: - ha_search_entities: now leads with "PRIMARY tool for finding entities by name" and redirects config searches to ha_deep_search - ha_deep_search: now opens with "not for finding entity IDs" and redirects entity lookups to ha_search_entities Verified with UAT runs: agent calls ha_search_entities for "find kitchen light" and ha_deep_search for "which automations reference light.bed_light". Also adds UAT story s13 covering the "find automations by referenced entity" workflow, which was missing from the catalog.
1 parent 7af5601 commit 51b9dca

2 files changed

Lines changed: 68 additions & 6 deletions

File tree

src/ha_mcp/tools/tools_search.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ async def ha_search_entities(
156156
] = 0,
157157
group_by_domain: bool | str = False,
158158
) -> dict[str, Any]:
159-
"""Comprehensive entity search with fuzzy matching, domain/area filtering, and optional grouping.
159+
"""PRIMARY tool for finding entities (lights, sensors, switches, etc.) by name, area, or domain. Use this first when looking up any entity ID.
160+
161+
For searching *inside* automation/script/helper configurations, use ha_deep_search instead.
160162
161163
**Listing Entities by Domain:**
162164
Use domain_filter with an empty query to list all entities of a specific type:
@@ -614,12 +616,15 @@ async def ha_deep_search(
614616
),
615617
] = False,
616618
) -> dict[str, Any]:
617-
"""Deep search across automation, script, and helper definitions.
619+
"""Search inside automation, script, and helper *configurations* — not for finding entity IDs.
620+
621+
Use this when you need to find automations/scripts by what they *do* (e.g., which automations
622+
call a specific service, reference a particular entity, or contain a certain action).
623+
For finding entity IDs by name, use ha_search_entities instead.
618624
619-
Searches not only entity names but also within configuration definitions including
620-
triggers, actions, sequences, and other config fields. Perfect for finding automations
621-
that use specific services, helpers referenced in scripts, or tracking down where
622-
particular entities are being used.
625+
Searches within configuration definitions including triggers, actions, sequences, and other
626+
config fields. Perfect for finding automations that use specific services, helpers referenced
627+
in scripts, or tracking down where particular entities are being used.
623628
624629
Args:
625630
query: Search query (can be partial, with typos)
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
id: s13
2+
title: "Find automations and scripts that reference a specific entity"
3+
category: automation
4+
weight: 3
5+
description: >
6+
User wants to know which automations or scripts use a specific entity.
7+
This requires searching inside configuration definitions (triggers, actions),
8+
not just entity names. A common troubleshooting workflow when a user wants
9+
to understand what controls a device or before renaming/removing an entity.
10+
11+
tags:
12+
- search
13+
- automation
14+
- script
15+
- deep_search
16+
17+
setup:
18+
- tool: ha_config_set_automation
19+
args:
20+
config:
21+
alias: "Bed Light Evening"
22+
description: "Turn on bed light in the evening"
23+
mode: single
24+
trigger:
25+
- platform: time
26+
at: "20:00:00"
27+
action:
28+
- action: light.turn_on
29+
target:
30+
entity_id: light.bed_light
31+
data:
32+
brightness_pct: 80
33+
34+
prompt: >
35+
Which automations or scripts reference light.bed_light? I want to know all the
36+
places in my configuration that use this entity.
37+
38+
teardown: []
39+
40+
verify:
41+
questions:
42+
- "Which automation references light.bed_light?"
43+
- "What does the automation do with light.bed_light?"
44+
- "Is this an automation, script, or both?"
45+
ha_checks:
46+
- type: automation_exists
47+
alias: "Bed Light Evening"
48+
- type: response_contains
49+
value: "Bed Light Evening"
50+
51+
expected:
52+
tools_should_use:
53+
- ha_deep_search
54+
description: >
55+
Agent should use ha_deep_search to search inside automation/script
56+
configurations for references to light.bed_light. A good agent will
57+
report the automation name, its purpose, and how it uses the entity.

0 commit comments

Comments
 (0)