From c4ecef54bc62f74aa2e17d3258a37b080cc52e46 Mon Sep 17 00:00:00 2001 From: Shangjie Chen Date: Fri, 9 May 2025 14:22:03 -0700 Subject: [PATCH] fix: Generate event id at beginning, and regen for every new yield event. This is because trace module requires an event id. PiperOrigin-RevId: 756905471 --- src/google/adk/flows/llm_flows/base_llm_flow.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/adk/flows/llm_flows/base_llm_flow.py b/src/google/adk/flows/llm_flows/base_llm_flow.py index 5268034..d5ab713 100644 --- a/src/google/adk/flows/llm_flows/base_llm_flow.py +++ b/src/google/adk/flows/llm_flows/base_llm_flow.py @@ -267,6 +267,7 @@ class BaseLlmFlow(ABC): # Calls the LLM. model_response_event = Event( + id=Event.new_id(), invocation_id=invocation_context.invocation_id, author=invocation_context.agent.name, branch=invocation_context.branch, @@ -278,8 +279,8 @@ class BaseLlmFlow(ABC): async for event in self._postprocess_async( invocation_context, llm_request, llm_response, model_response_event ): - # Use a new id for every event. - event.id = Event.new_id() + # Update the mutable event id to avoid conflict + model_response_event.id = Event.new_id() yield event async def _preprocess_async(