Make sure we always have agent_id in ConversationInput (#137679)

* Make sure we always have agent_id in ConversationInput

* fix type
This commit is contained in:
Paulus Schoutsen 2025-02-07 21:25:21 -05:00 committed by GitHub
parent 61d1b34cef
commit 7883106e7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 14 additions and 11 deletions

View File

@ -79,6 +79,9 @@ async def async_converse(
extra_system_prompt: str | None = None,
) -> ConversationResult:
"""Process text and get intent."""
if agent_id is None:
agent_id = HOME_ASSISTANT_AGENT
agent = async_get_agent(hass, agent_id)
if agent is None:

View File

@ -381,7 +381,7 @@ class DefaultAgent(ConversationEntity):
speech: str = response.speech.get("plain", {}).get("speech", "")
chat_log.async_add_assistant_content_without_tools(
AssistantContent(
agent_id=user_input.agent_id, # type: ignore[arg-type]
agent_id=user_input.agent_id,
content=speech,
)
)

View File

@ -195,7 +195,7 @@ async def websocket_hass_agent_debug(
conversation_id=None,
device_id=msg.get("device_id"),
language=msg.get("language", hass.config.language),
agent_id=None,
agent_id=agent.entity_id,
)
result_dict: dict[str, Any] | None = None

View File

@ -37,7 +37,7 @@ class ConversationInput:
language: str
"""Language of the request."""
agent_id: str | None = None
agent_id: str
"""Agent to use for processing."""
extra_system_prompt: str | None = None

View File

@ -261,8 +261,6 @@ class GoogleGenerativeAIConversationEntity(
chat_log: conversation.ChatLog,
) -> conversation.ConversationResult:
"""Call the API."""
assert user_input.agent_id
options = self.entry.options
try:

View File

@ -198,7 +198,6 @@ class OpenAIConversationEntity(
chat_log: conversation.ChatLog,
) -> conversation.ConversationResult:
"""Call the API."""
assert user_input.agent_id
options = self.entry.options
try:

View File

@ -271,6 +271,7 @@ async def test_async_handle_sentence_triggers(
text="my trigger",
context=Context(),
conversation_id=None,
agent_id=conversation.HOME_ASSISTANT_AGENT,
device_id=device_id,
language=hass.config.language,
),
@ -306,6 +307,7 @@ async def test_async_handle_intents(hass: HomeAssistant) -> None:
ConversationInput(
text="I'd like to order a stout",
context=Context(),
agent_id=conversation.HOME_ASSISTANT_AGENT,
conversation_id=None,
device_id=None,
language=hass.config.language,
@ -321,6 +323,7 @@ async def test_async_handle_intents(hass: HomeAssistant) -> None:
hass,
ConversationInput(
text="this sentence does not exist",
agent_id=conversation.HOME_ASSISTANT_AGENT,
context=Context(),
conversation_id=None,
device_id=None,

View File

@ -5,7 +5,7 @@ import logging
import pytest
import voluptuous as vol
from homeassistant.components.conversation import default_agent
from homeassistant.components.conversation import HOME_ASSISTANT_AGENT, default_agent
from homeassistant.components.conversation.const import DATA_DEFAULT_ENTITY
from homeassistant.components.conversation.models import ConversationInput
from homeassistant.core import Context, HomeAssistant, ServiceCall
@ -82,7 +82,7 @@ async def test_if_fires_on_event(
"details": {},
"device_id": None,
"user_input": {
"agent_id": None,
"agent_id": HOME_ASSISTANT_AGENT,
"context": context.as_dict(),
"conversation_id": None,
"device_id": None,
@ -230,7 +230,7 @@ async def test_response_same_sentence(
"details": {},
"device_id": None,
"user_input": {
"agent_id": None,
"agent_id": HOME_ASSISTANT_AGENT,
"context": context.as_dict(),
"conversation_id": None,
"device_id": None,
@ -408,7 +408,7 @@ async def test_same_trigger_multiple_sentences(
"details": {},
"device_id": None,
"user_input": {
"agent_id": None,
"agent_id": HOME_ASSISTANT_AGENT,
"context": context.as_dict(),
"conversation_id": None,
"device_id": None,
@ -636,7 +636,7 @@ async def test_wildcards(hass: HomeAssistant, service_calls: list[ServiceCall])
},
"device_id": None,
"user_input": {
"agent_id": None,
"agent_id": HOME_ASSISTANT_AGENT,
"context": context.as_dict(),
"conversation_id": None,
"device_id": None,