Skip to content

Commit f8a6bd7

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: include intermediate subagent final response events in evaluation intermediate data
PiperOrigin-RevId: 891846041
1 parent d689a04 commit f8a6bd7

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/google/adk/evaluation/evaluation_generator.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ def convert_events_to_eval_invocations(
280280
invocations = []
281281
for invocation_id, events in events_by_invocation_id.items():
282282
final_response = None
283+
final_event = None
283284
user_content = Content(parts=[])
284285
invocation_timestamp = 0
285286
app_details = None
@@ -304,15 +305,17 @@ def convert_events_to_eval_invocations(
304305
if event.content and event.content.parts:
305306
if event.is_final_response():
306307
final_response = event.content
307-
else:
308-
for p in event.content.parts:
309-
if p.function_call or p.function_response or p.text:
310-
events_to_add.append(event)
311-
break
308+
final_event = event
309+
310+
for p in event.content.parts:
311+
if p.function_call or p.function_response or p.text:
312+
events_to_add.append(event)
313+
break
312314

313315
invocation_events = [
314316
InvocationEvent(author=e.author, content=e.content)
315317
for e in events_to_add
318+
if e is not final_event
316319
]
317320
invocations.append(
318321
Invocation(

tests/unittests/evaluation/test_evaluation_generator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,28 @@ def test_multi_agent(
204204
assert events[2].author == "sub_agent_1"
205205
assert events[3].author == "sub_agent_2"
206206

207+
def test_convert_multi_agent_final_responses(
208+
self,
209+
):
210+
"""Tests that only the last final response is excluded from intermediate data."""
211+
events = [
212+
_build_event("user", [types.Part(text="Hello")], "inv1"),
213+
_build_event("agent1", [types.Part(text="First response")], "inv1"),
214+
_build_event("agent2", [types.Part(text="Second response")], "inv1"),
215+
]
216+
217+
invocations = EvaluationGenerator.convert_events_to_eval_invocations(events)
218+
219+
assert len(invocations) == 1
220+
invocation = invocations[0]
221+
assert invocation.final_response.parts[0].text == "Second response"
222+
223+
intermediate_events = invocation.intermediate_data.invocation_events
224+
# agent1 is included because it is not the final_event (which is agent2)
225+
assert len(intermediate_events) == 1
226+
assert intermediate_events[0].author == "agent1"
227+
assert intermediate_events[0].content.parts[0].text == "First response"
228+
207229

208230
class TestGetAppDetailsByInvocationId:
209231
"""Test cases for EvaluationGenerator._get_app_details_by_invocation_id method."""

0 commit comments

Comments
 (0)