diff --git a/homeassistant/components/conversation/chat_log.py b/homeassistant/components/conversation/chat_log.py index 1ee5e9965ab..19482af1983 100644 --- a/homeassistant/components/conversation/chat_log.py +++ b/homeassistant/components/conversation/chat_log.py @@ -49,7 +49,11 @@ def async_get_chat_log( raise RuntimeError( "Cannot attach chat log delta listener unless initial caller" ) - if user_input is not None: + if user_input is not None and ( + (content := chat_log.content[-1]).role != "user" + # MyPy doesn't understand that content is a UserContent here + or content.content != user_input.text # type: ignore[union-attr] + ): chat_log.async_add_user_content(UserContent(content=user_input.text)) yield chat_log diff --git a/tests/components/conversation/test_chat_log.py b/tests/components/conversation/test_chat_log.py index a4dc9b819c1..c0687ebecfb 100644 --- a/tests/components/conversation/test_chat_log.py +++ b/tests/components/conversation/test_chat_log.py @@ -86,7 +86,9 @@ async def test_default_content( with ( chat_session.async_get_chat_session(hass) as session, async_get_chat_log(hass, session, mock_conversation_input) as chat_log, + async_get_chat_log(hass, session, mock_conversation_input) as chat_log2, ): + assert chat_log is chat_log2 assert len(chat_log.content) == 2 assert chat_log.content[0].role == "system" assert chat_log.content[0].content == ""