Remove entity state from mcp-server prompt (#137126)

* Create a stateless assist API for MCP server

* Update stateless API

* Fix areas in exposed entity fields

* Add tests that verify areas are returned

* Revert the getstate intent

* Revert whitespace change

* Revert whitespace change

* Revert method name changes to avoid breaking openai and google tests
This commit is contained in:
Allen Porter
2025-02-01 14:26:52 -08:00
committed by GitHub
parent 2c99e3778e
commit bf6f790d09
7 changed files with 109 additions and 14 deletions

View File

@@ -326,12 +326,21 @@ class AssistAPI(API):
def _async_get_api_prompt(
self, llm_context: LLMContext, exposed_entities: dict | None
) -> str:
"""Return the prompt for the API."""
if not exposed_entities:
return (
"Only if the user wants to control a device, tell them to expose entities "
"to their voice assistant in Home Assistant."
)
return "\n".join(
[
*self._async_get_preable(llm_context),
*self._async_get_exposed_entities_prompt(llm_context, exposed_entities),
]
)
@callback
def _async_get_preable(self, llm_context: LLMContext) -> list[str]:
"""Return the prompt for the API."""
prompt = [
(
@@ -371,13 +380,22 @@ class AssistAPI(API):
):
prompt.append("This device is not able to start timers.")
return prompt
@callback
def _async_get_exposed_entities_prompt(
self, llm_context: LLMContext, exposed_entities: dict | None
) -> list[str]:
"""Return the prompt for the API for exposed entities."""
prompt = []
if exposed_entities:
prompt.append(
"An overview of the areas and the devices in this smart home:"
)
prompt.append(yaml_util.dump(list(exposed_entities.values())))
return "\n".join(prompt)
return prompt
@callback
def _async_get_tools(