Home Assistant Unofficial Reference 2024.12.1
models.py
Go to the documentation of this file.
1 """Agent foundation for conversation integration."""
2 
3 from __future__ import annotations
4 
5 from abc import ABC, abstractmethod
6 from dataclasses import dataclass
7 from typing import Any, Literal
8 
9 from homeassistant.core import Context
10 from homeassistant.helpers import intent
11 
12 
13 @dataclass(frozen=True)
14 class AgentInfo:
15  """Container for conversation agent info."""
16 
17  id: str
18  name: str
19 
20 
21 @dataclass(slots=True)
23  """User input to be processed."""
24 
25  text: str
26  """User spoken text."""
27 
28  context: Context
29  """Context of the request."""
30 
31  conversation_id: str | None
32  """Unique identifier for the conversation."""
33 
34  device_id: str | None
35  """Unique identifier for the device."""
36 
37  language: str
38  """Language of the request."""
39 
40  agent_id: str | None = None
41  """Agent to use for processing."""
42 
43 
44 @dataclass(slots=True)
46  """Result of async_process."""
47 
48  response: intent.IntentResponse
49  conversation_id: str | None = None
50 
51  def as_dict(self) -> dict[str, Any]:
52  """Return result as a dict."""
53  return {
54  "response": self.response.as_dict(),
55  "conversation_id": self.conversation_id,
56  }
57 
58 
60  """Abstract conversation agent."""
61 
62  @property
63  @abstractmethod
64  def supported_languages(self) -> list[str] | Literal["*"]:
65  """Return a list of supported languages."""
66 
67  @abstractmethod
68  async def async_process(self, user_input: ConversationInput) -> ConversationResult:
69  """Process a sentence."""
70 
71  async def async_reload(self, language: str | None = None) -> None:
72  """Clear cached intents for a language."""
73 
74  async def async_prepare(self, language: str | None = None) -> None:
75  """Load intents for a language."""
ConversationResult async_process(self, ConversationInput user_input)
Definition: models.py:68