|
37 | 37 | from google.genai._gaos.types.interactions import functionresultstep |
38 | 38 | from google.genai._gaos.types.interactions import modeloutputstep |
39 | 39 | from google.genai._gaos.types.interactions import userinputstep |
| 40 | + |
| 41 | +try: |
| 42 | + from google.genai._gaos.utils.serializers import ALLOW_UNKNOWN_UNION_VARIANTS |
| 43 | +except (ImportError, AttributeError): |
| 44 | + ALLOW_UNKNOWN_UNION_VARIANTS = "speakeasy_allow_unknown_union_variants" |
40 | 45 | from google.genai.models import Models |
41 | 46 | import pandas as pd |
42 | 47 | from tqdm import tqdm |
@@ -775,7 +780,16 @@ def _interaction_dict_to_agent_data( |
775 | 780 | Returns: |
776 | 781 | An AgentData object with one or more ConversationTurns. |
777 | 782 | """ |
778 | | - typed_interaction = interaction_types.Interaction.model_validate(interaction) |
| 783 | + # A server response, so unknown step types must degrade rather than raise. |
| 784 | + # `Step` is an open discriminated union: parse_open_union only falls back to |
| 785 | + # the Unknown variant when the validation context carries |
| 786 | + # ALLOW_UNKNOWN_UNION_VARIANTS, and raises without it so that a |
| 787 | + # user-constructed request payload surfaces its mistakes locally. This |
| 788 | + # payload comes off the Interactions API, so it is on the tolerant side of |
| 789 | + # that line. _interaction_steps_to_events already drops steps it cannot map. |
| 790 | + typed_interaction = interaction_types.Interaction.model_validate( |
| 791 | + interaction, context={ALLOW_UNKNOWN_UNION_VARIANTS: True} |
| 792 | + ) |
779 | 793 | all_events = _interaction_steps_to_events(typed_interaction.steps or []) |
780 | 794 |
|
781 | 795 | # Group events into turns. Each UserInputStep starts a new turn. |
@@ -1689,8 +1703,12 @@ def _resolve_interactions_to_eval_cases( |
1689 | 1703 | break |
1690 | 1704 | interaction_dict = json.loads(response.body) |
1691 | 1705 | try: |
| 1706 | + # Also a server response -- see _interaction_dict_to_agent_data. |
| 1707 | + # Without the context a single step type this client does not |
| 1708 | + # know about raised, and the except below turned that into a |
| 1709 | + # `break`, silently truncating the interaction history. |
1692 | 1710 | typed_interaction = interaction_types.Interaction.model_validate( |
1693 | | - interaction_dict |
| 1711 | + interaction_dict, context={ALLOW_UNKNOWN_UNION_VARIANTS: True} |
1694 | 1712 | ) |
1695 | 1713 | except Exception as e: |
1696 | 1714 | logger.warning("Failed to validate interaction model: %s", e) |
|
0 commit comments