From dedec6431d93f0bc1f46380b4df857f9ce5875ab Mon Sep 17 00:00:00 2001 From: MisterTK Date: Wed, 3 Dec 2025 21:32:05 -0600 Subject: [PATCH] fix(adk): resolve multi-turn conversation failure with None user_message Fix two bugs in adk_agent.py that caused multi-turn conversations to fail with "Both invocation_id and new_message are None" error on the second message. Bug 1: The conditional `if message_batch else None` incorrectly set user_message to None when message_batch was not explicitly passed, even when unseen_messages contained valid user messages. Bug 2: When unseen_messages was empty (because all messages were already marked as processed by ID), there was no fallback to extract the latest user message from input.messages. Fixes #769 --- .../adk-middleware/python/src/ag_ui_adk/adk_agent.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/integrations/adk-middleware/python/src/ag_ui_adk/adk_agent.py b/integrations/adk-middleware/python/src/ag_ui_adk/adk_agent.py index d9d50f665..0e274784a 100644 --- a/integrations/adk-middleware/python/src/ag_ui_adk/adk_agent.py +++ b/integrations/adk-middleware/python/src/ag_ui_adk/adk_agent.py @@ -1077,7 +1077,10 @@ async def _run_adk_in_background( self._session_manager.mark_messages_processed(app_name, input.thread_id, message_ids) # Convert user messages first (if any) - user_message = await self._convert_latest_message(input, unseen_messages) if message_batch else None + # Note: We pass unseen_messages which is already set from message_batch or _get_unseen_messages + # The original code had a bug: `if message_batch else None` would skip conversion when + # message_batch was None but unseen_messages contained valid user messages + user_message = await self._convert_latest_message(input, unseen_messages) # if there is a tool response submission by the user, add FunctionResponse to session first if active_tool_results and user_message: @@ -1185,6 +1188,10 @@ async def _run_adk_in_background( new_message = types.Content(parts=function_response_parts, role='user') else: # No tool results, just use the user message + # If user_message is None (e.g., unseen_messages was empty because all were + # already processed), fall back to extracting the latest user message from input.messages + if user_message is None and input.messages: + user_message = await self._convert_latest_message(input, input.messages) new_message = user_message # Create event translator