adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

invocation_id mismatch in merge_parallel_function_response_events creates new event_id instead of reusing original invocation_id

Open jinookkoo opened this issue 1 year ago • 4 comments

Describe the bug

The merge_parallel_function_response_events function (L484) in src/google/adk/flows/llm_flows/functions.py generates a new invocation_id using Event.new_id() for function_response data, instead of reusing the base_event's invocation_id.

This leads to function_response data being associated with a separate invocation ID (in the event ID format), making it impossible to query this data by the original invocation_id. When aggregating data, this often results in the function_response data not being correctly included within its respective invocation.

To Reproduce

Currently, I don't have a direct set of reproduction steps that can be run as a simple script without access to internal ADK testing environments or more complex setups. However, the issue can be observed by inspecting the invocation_id of function_response events generated by the merge_parallel_function_response_events function and comparing them to the invocation_id of the base_event from which they originated.

Expected behavior

The function_response data should retain the same invocation_id as the function_call that triggered it and the base_event it belongs to. This would allow for proper data aggregation and querying based on the invocation_id.

Screenshots

N/A

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): 3.12.10
  • ADK version(pip show google-adk): 1.2.1

Additional context

The primary concern is data consistency and queryability. By generating a new invocation_id, the function_response effectively becomes an orphaned event in terms of its relation to the original invocation, complicating debugging, monitoring, and analysis of LLM flow executions. It would be beneficial to understand the rationale behind generating a new ID in this specific case, as it deviates from the expected behavior of keeping related events under a single invocation ID.

jinookkoo avatar Jun 20 '25 02:06 jinookkoo

~~If calling OpenAI's ChatGPT (LiteLLM) instead of Gemini, the following error occurs and tool calls are not processed correctly.~~

~~litellm.BadRequestError: OpenAIException - An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages~~

This error log is unrelated to this issue.

jinookkoo avatar Jul 17 '25 02:07 jinookkoo

Is there a reason to use base_event.new_id() instead of base_event.invocation_id?

https://github.com/google/adk-python/blob/a17ebe6ebd7b58fa86a90cceb7650c2b3187933d/src/google/adk/flows/llm_flows/functions.py#L513

jinookkoo avatar Jul 17 '25 02:07 jinookkoo

That's a good catch! It's a bug.

@seanzhou1023 could you fix?

Jacksunwei avatar Aug 14 '25 23:08 Jacksunwei

sure, working on it. Thanks for reporting the issue.

seanzhou1023 avatar Aug 15 '25 22:08 seanzhou1023