Skip to content

Commit dedec64

Browse files
committed
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
1 parent 76914c2 commit dedec64

File tree

1 file changed

+8
-1
lines changed
  • integrations/adk-middleware/python/src/ag_ui_adk

1 file changed

+8
-1
lines changed

integrations/adk-middleware/python/src/ag_ui_adk/adk_agent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,10 @@ async def _run_adk_in_background(
10771077
self._session_manager.mark_messages_processed(app_name, input.thread_id, message_ids)
10781078

10791079
# Convert user messages first (if any)
1080-
user_message = await self._convert_latest_message(input, unseen_messages) if message_batch else None
1080+
# Note: We pass unseen_messages which is already set from message_batch or _get_unseen_messages
1081+
# The original code had a bug: `if message_batch else None` would skip conversion when
1082+
# message_batch was None but unseen_messages contained valid user messages
1083+
user_message = await self._convert_latest_message(input, unseen_messages)
10811084

10821085
# if there is a tool response submission by the user, add FunctionResponse to session first
10831086
if active_tool_results and user_message:
@@ -1185,6 +1188,10 @@ async def _run_adk_in_background(
11851188
new_message = types.Content(parts=function_response_parts, role='user')
11861189
else:
11871190
# No tool results, just use the user message
1191+
# If user_message is None (e.g., unseen_messages was empty because all were
1192+
# already processed), fall back to extracting the latest user message from input.messages
1193+
if user_message is None and input.messages:
1194+
user_message = await self._convert_latest_message(input, input.messages)
11881195
new_message = user_message
11891196

11901197
# Create event translator

0 commit comments

Comments
 (0)