Skip to content

Commit 3f3aa7b

Browse files
seanzhougooglecopybara-github
authored andcommitted
fix: Set invocation_id and branch for event generated when both output_schema and tools are used
fixes #2631 PiperOrigin-RevId: 797843460
1 parent 826f554 commit 3f3aa7b

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/google/adk/flows/llm_flows/_output_schema_processor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ def create_final_model_response_event(
7878
from google.genai import types
7979

8080
# Create a proper model response event
81-
final_event = Event(author=invocation_context.agent.name)
81+
final_event = Event(
82+
author=invocation_context.agent.name,
83+
invocation_id=invocation_context.invocation_id,
84+
branch=invocation_context.branch,
85+
)
8286
final_event.content = types.Content(
8387
role='model', parts=[types.Part(text=json_response)]
8488
)

tests/unittests/flows/llm_flows/test_output_schema_processor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ async def test_output_schema_helper_functions():
230230
# Test create_final_model_response_event function
231231
final_event = create_final_model_response_event(invocation_context, test_json)
232232
assert final_event.author == 'test_agent'
233+
assert final_event.invocation_id == invocation_context.invocation_id
234+
assert final_event.branch == invocation_context.branch
233235
assert final_event.content.role == 'model'
234236
assert final_event.content.parts[0].text == test_json
235237

@@ -348,6 +350,8 @@ async def test_flow_yields_both_events_for_set_model_response():
348350
# Second event should be the final model response with JSON
349351
second_event = events[1]
350352
assert second_event.author == 'test_agent'
353+
assert second_event.invocation_id == invocation_context.invocation_id
354+
assert second_event.branch == invocation_context.branch
351355
assert second_event.content.role == 'model'
352356
assert (
353357
second_event.content.parts[0].text

0 commit comments

Comments
 (0)