Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/google/adk/evaluation/evaluation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/unittests/evaluation/test_evaluation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand Down