Standardize conversation agents passing in ChatSession #1191
-
ContextThere is a new helper called ChatSession to handle ongoing conversations, and conversation provides ChatLog as a way to attach messages to a conversation. Instead of requiring all conversation agents to request it, we can standardize a new method, in a backwards compatible way to pass this in. Old method to process an incoming chat from a user: async def async_process(
self, user_input: conversation.ConversationInput
) -> conversation.ConversationResult:
"""Process a sentence.""" ProposalThe proposal is to change it to the following: async def async_process(
self, user_input: conversation.ConversationInput
) -> conversation.ConversationResult:
"""Process a sentence."""
with (
chat_session.async_get_chat_session(
self.hass, user_input.conversation_id
) as session,
conversation.async_get_chat_log(self.hass, session, user_input) as chat_log,
):
return await self._async_handle_message(user_input, chat_log)
async def _async_handle_message(
self,
user_input: conversation.ConversationInput,
chat_log: conversation.ChatLog,
) -> conversation.ConversationResult:
"""Call the API.""" Conversation agents that leverage ChatSession and ChatLog can migrate their code to use the new This approach is already being used by all conversation agents: OpenAI, Google, Anthropic and Ollama. AlternativesWe can inspect the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Generally: Looks good to me. This seems like a good simple step forward as we expand the capabilities of Do we want |
Beta Was this translation helpful? Give feedback.
-
This was discussed and approved in the architecture meeting ✅ |
Beta Was this translation helpful? Give feedback.
This was discussed and approved in the architecture meeting ✅