Skip to content

Conversation

@MisterTK
Copy link

@MisterTK MisterTK commented Dec 4, 2025

Summary

  • Fix two bugs in adk_agent.py that caused multi-turn conversations to fail with ValueError: Both invocation_id and new_message are None error on the second message

Problem

When using CopilotKit with ag-ui-adk, multi-turn conversations fail on the second message. The first message works correctly, but subsequent messages throw the error from Google ADK.

Root Cause

Two bugs combine to cause this issue:

Bug 1: Incorrect conditional (line 1080)

# Buggy:
user_message = await self._convert_latest_message(input, unseen_messages) if message_batch else None

The condition if message_batch else None incorrectly sets user_message to None when message_batch was not explicitly passed (which is the normal case for direct calls via the run method), even when unseen_messages contained valid user messages.

Bug 2: No fallback when unseen_messages is empty (line ~1187)

When unseen_messages is empty (because all messages were already marked as "processed" by ID), there was no fallback to extract the latest user message from input.messages. This happens when:

  1. CopilotKit sends all messages with the same or reused IDs
  2. The first request marks message IDs as processed
  3. On the second request, _get_unseen_messages() returns empty
  4. Code falls through without a valid user message
  5. Google ADK throws the error

Solution

  1. Remove the incorrect conditional so _convert_latest_message is always called when there are unseen messages
  2. Add a fallback to extract from input.messages when user_message is None

Test Plan

  • Tested with CopilotKit frontend - multi-turn conversations now work correctly
  • First message: 200 OK with RUN_STARTED -> TEXT_MESSAGE -> RUN_FINISHED
  • Second message (previously failed): 200 OK with same event sequence
  • Third+ messages: Continue to work correctly

Fixes #769

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 ag-ui-protocol#769
@contextablemark
Copy link
Collaborator

Hi @MisterTK - Thank you for your analysis and for proposing a fix. Would it be possible to add a test (under https://github.com/ag-ui-protocol/ag-ui/tree/main/integrations/adk-middleware/python/tests) to simulate this sequence in order to help verify the fix and guard against regressions in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Multi-turn conversation fails with 'Both invocation_id and new_message are None' in ag-ui-adk

2 participants