Skip to content
Merged
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
22 changes: 20 additions & 2 deletions agentplatform/_genai/_evals_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
from google.genai._gaos.types.interactions import functionresultstep
from google.genai._gaos.types.interactions import modeloutputstep
from google.genai._gaos.types.interactions import userinputstep

try:
from google.genai._gaos.utils.serializers import ALLOW_UNKNOWN_UNION_VARIANTS
except (ImportError, AttributeError):
ALLOW_UNKNOWN_UNION_VARIANTS = "speakeasy_allow_unknown_union_variants"
from google.genai.models import Models
import pandas as pd
from tqdm import tqdm
Expand Down Expand Up @@ -775,7 +780,16 @@ def _interaction_dict_to_agent_data(
Returns:
An AgentData object with one or more ConversationTurns.
"""
typed_interaction = interaction_types.Interaction.model_validate(interaction)
# A server response, so unknown step types must degrade rather than raise.
# `Step` is an open discriminated union: parse_open_union only falls back to
# the Unknown variant when the validation context carries
# ALLOW_UNKNOWN_UNION_VARIANTS, and raises without it so that a
# user-constructed request payload surfaces its mistakes locally. This
# payload comes off the Interactions API, so it is on the tolerant side of
# that line. _interaction_steps_to_events already drops steps it cannot map.
typed_interaction = interaction_types.Interaction.model_validate(
interaction, context={ALLOW_UNKNOWN_UNION_VARIANTS: True}
)
all_events = _interaction_steps_to_events(typed_interaction.steps or [])

# Group events into turns. Each UserInputStep starts a new turn.
Expand Down Expand Up @@ -1689,8 +1703,12 @@ def _resolve_interactions_to_eval_cases(
break
interaction_dict = json.loads(response.body)
try:
# Also a server response -- see _interaction_dict_to_agent_data.
# Without the context a single step type this client does not
# know about raised, and the except below turned that into a
# `break`, silently truncating the interaction history.
typed_interaction = interaction_types.Interaction.model_validate(
interaction_dict
interaction_dict, context={ALLOW_UNKNOWN_UNION_VARIANTS: True}
)
except Exception as e:
logger.warning("Failed to validate interaction model: %s", e)
Expand Down
Loading