Ensure sentence triggers are only checked once (#131210)

Co-authored-by: Artur Pragacz <49985303+arturpragacz@users.noreply.github.com>
pull/127580/merge
Michael Hansen 2024-11-22 10:38:19 -06:00 committed by GitHub
parent 754cf1fdb4
commit 7621012ee6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 37 additions and 32 deletions

View File

@ -1032,6 +1032,8 @@ class PipelineRun:
agent_id=self.intent_agent,
)
conversation_result: conversation.ConversationResult | None = None
if user_input.agent_id != conversation.HOME_ASSISTANT_AGENT:
# Sentence triggers override conversation agent
if (
trigger_response_text
@ -1049,22 +1051,18 @@ class PipelineRun:
conversation_id=user_input.conversation_id,
)
# Try local intents first, if preferred.
# Skip this step if the default agent is already used.
elif (
self.pipeline.prefer_local_intents
and (user_input.agent_id != conversation.HOME_ASSISTANT_AGENT)
and (
elif self.pipeline.prefer_local_intents and (
intent_response := await conversation.async_handle_intents(
self.hass, user_input
)
)
):
# Local intent matched
conversation_result = conversation.ConversationResult(
response=intent_response,
conversation_id=user_input.conversation_id,
)
else:
if conversation_result is None:
# Fall back to pipeline conversation agent
conversation_result = await conversation.async_converse(
hass=self.hass,

View File

@ -941,7 +941,7 @@ async def test_sentence_trigger_overrides_conversation_agent(
init_components,
pipeline_data: assist_pipeline.pipeline.PipelineData,
) -> None:
"""Test that sentence triggers are checked before the conversation agent."""
"""Test that sentence triggers are checked before a non-default conversation agent."""
assert await async_setup_component(
hass,
"automation",
@ -975,8 +975,15 @@ async def test_sentence_trigger_overrides_conversation_agent(
start_stage=assist_pipeline.PipelineStage.INTENT,
end_stage=assist_pipeline.PipelineStage.INTENT,
event_callback=events.append,
intent_agent="test-agent", # not the default agent
),
)
# Ensure prepare succeeds
with patch(
"homeassistant.components.assist_pipeline.pipeline.conversation.async_get_agent_info",
return_value=conversation.AgentInfo(id="test-agent", name="Test Agent"),
):
await pipeline_input.validate()
with patch(