Skip to content

Commit b549ab4

Browse files
GWealecopybara-github
authored andcommitted
fix: make InvocationEvent.content optional so the Web UI can save eval cases
InvocationEvent.content was typed Optional[Content] but had no default. Under Pydantic v2 an Optional field without a default is still required, so saving an eval case whose event carries no content (as the Web UI does) failed model validation and the save PUT returned HTTP 422. Default content to None so an omitted or empty content is accepted. Close google#6336 Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 951053413
1 parent 1890557 commit b549ab4

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/google/adk/evaluation/eval_case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class InvocationEvent(EvalBaseModel):
6464
author: str
6565
"""The name of the agent that authored/owned this event."""
6666

67-
content: Optional[genai_types.Content]
67+
content: Optional[genai_types.Content] = None
6868
"""The content of the event."""
6969

7070

tests/unittests/evaluation/test_eval_case.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def test_eval_models_preserve_extra_metadata():
5454
assert dumped['session_input']['source'] == 'nightly'
5555

5656

57+
def test_invocation_event_content_defaults_to_none():
58+
"""An InvocationEvent can be built and round-tripped without content."""
59+
event = InvocationEvent(author='agent')
60+
61+
assert event.content is None
62+
assert InvocationEvent.model_validate(event.model_dump()).content is None
63+
64+
5765
def test_get_all_tool_calls_with_none_input():
5866
"""Tests that an empty list is returned when intermediate_data is None."""
5967
assert get_all_tool_calls(None) == []

0 commit comments

Comments
 (0)