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
This commit is contained in:
Shangjie Chen 2025-05-09 14:22:03 -07:00 committed by Copybara-Service
parent 415104743d
commit c4ecef54bc

View File

@ -267,6 +267,7 @@ class BaseLlmFlow(ABC):
# Calls the LLM. # Calls the LLM.
model_response_event = Event( model_response_event = Event(
id=Event.new_id(),
invocation_id=invocation_context.invocation_id, invocation_id=invocation_context.invocation_id,
author=invocation_context.agent.name, author=invocation_context.agent.name,
branch=invocation_context.branch, branch=invocation_context.branch,
@ -278,8 +279,8 @@ class BaseLlmFlow(ABC):
async for event in self._postprocess_async( async for event in self._postprocess_async(
invocation_context, llm_request, llm_response, model_response_event invocation_context, llm_request, llm_response, model_response_event
): ):
# Use a new id for every event. # Update the mutable event id to avoid conflict
event.id = Event.new_id() model_response_event.id = Event.new_id()
yield event yield event
async def _preprocess_async( async def _preprocess_async(