From 5531740cb930a932d7cd2eaef2a1b6b4484ffcd0 Mon Sep 17 00:00:00 2001 From: Nachiket Date: Sat, 6 Jun 2026 09:24:54 -0700 Subject: [PATCH] fix(evals): skip invocations without user events --- .../adk/evaluation/evaluation_generator.py | 5 ++++- .../evaluation/test_evaluation_generator.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/google/adk/evaluation/evaluation_generator.py b/src/google/adk/evaluation/evaluation_generator.py index 5b0100818c..4f37d6b31e 100644 --- a/src/google/adk/evaluation/evaluation_generator.py +++ b/src/google/adk/evaluation/evaluation_generator.py @@ -627,7 +627,7 @@ def convert_events_to_eval_invocations( for invocation_id, events in events_by_invocation_id.items(): final_response = None final_event = None - user_content = Content(parts=[]) + user_content = None invocation_timestamp = 0 app_details = None if ( @@ -663,6 +663,9 @@ def convert_events_to_eval_invocations( events_to_add.append(event) break + if user_content is None: + continue + invocation_events = [ InvocationEvent(author=e.author, content=e.content) for e in events_to_add diff --git a/tests/unittests/evaluation/test_evaluation_generator.py b/tests/unittests/evaluation/test_evaluation_generator.py index 05ab25cc72..a1cbf8fcc6 100644 --- a/tests/unittests/evaluation/test_evaluation_generator.py +++ b/tests/unittests/evaluation/test_evaluation_generator.py @@ -70,6 +70,23 @@ def test_convert_single_turn_text_only( assert invocation.final_response.parts[0].text == "Hi there!" assert len(invocation.intermediate_data.invocation_events) == 0 + def test_skips_invocation_without_user_event( + self, + ): + """Tests that agent-only invocations are not converted to eval turns.""" + events = [ + _build_event("agent", [types.Part(text="Internal response")], "inv1"), + _build_event("user", [types.Part(text="Hello")], "inv2"), + _build_event("agent", [types.Part(text="Hi there!")], "inv2"), + ] + + invocations = EvaluationGenerator.convert_events_to_eval_invocations(events) + + assert len(invocations) == 1 + assert invocations[0].invocation_id == "inv2" + assert invocations[0].user_content.parts[0].text == "Hello" + assert invocations[0].final_response.parts[0].text == "Hi there!" + def test_convert_single_turn_tool_call( self, ):