Skip to content

fix: _EvalMetricResultWithInvocation handles expected_invocation gracefully#4665

Open
morganroux wants to merge 5 commits intogoogle:mainfrom
morganroux:fix/issue-4283
Open

fix: _EvalMetricResultWithInvocation handles expected_invocation gracefully#4665
morganroux wants to merge 5 commits intogoogle:mainfrom
morganroux:fix/issue-4283

Conversation

@morganroux
Copy link

@morganroux morganroux commented Mar 1, 2026

Link to Issue or Description of Change

Problem:

_EvalMetricResultWithInvocation expects expected_invocation to be set.
Needs to handle None value gracefully

Solution:

The two changes are in evaluation/agent_evaluator.py:
(1) line 93 — expected_invocation: Optional[Invocation] = None, and
(2) _print_details() lines 440-449 —null-guard all accesses to expected_invocation fields since it's None for conversation_scenario runs.

In order not to break the tabulate l.465 the concerned strings are defaulted to empty string.

Testing Plan

2 tests are created to validate this PR.

  • tests/integration/test_conversation_scenario.py
  • tests/unittests/evaluation/test_agent_evaluator.py

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Manual End-to-End (E2E) Tests:

N/A

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

N/A

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where the _EvalMetricResultWithInvocation class and related printing logic expected expected_invocation to always be present, leading to errors when it was None (e.g., during conversation_scenario runs). The changes ensure that None values for invocation objects are handled gracefully throughout the evaluation process, improving the robustness of the agent evaluation system.

Highlights

  • Optional Invocation: The expected_invocation field in the _EvalMetricResultWithInvocation class has been made optional, allowing it to be None.
  • Graceful Handling of None: Null-guard checks have been implemented in the _print_details function to safely handle cases where expected_invocation or actual_invocation might be None, preventing attribute access errors.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/google/adk/evaluation/agent_evaluator.py
    • Modified the _EvalMetricResultWithInvocation class to declare expected_invocation as Optional[Invocation] with a default value of None.
    • Introduced null-guard checks for all accesses to expected_invocation fields within the _print_details function.
    • Added null-guard checks for actual_invocation fields within the _print_details function for robustness.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot adk-bot added the eval [Component] This issue is related to evaluation label Mar 1, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Mar 1, 2026

Response from ADK Triaging Agent

Hello @morganroux, thank you for creating this PR!

Could you please provide a summary of passed pytest results and details for manual end-to-end (E2E) tests? This information will help reviewers to review your PR more efficiently. Thanks!

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly makes expected_invocation optional to handle cases where it might be None. The added null-guards for expected_invocation are appropriate. However, the pull request also introduces unnecessary null-guards for actual_invocation, which is a non-optional field. I've added specific comments to address this and suggest removing the redundant checks to maintain code clarity and correctness according to the data model.

Comment on lines 445 to 447
"actual_response": AgentEvaluator._convert_content_to_text(
per_invocation_result.actual_invocation.final_response
),
) if per_invocation_result.actual_invocation else None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The null check for actual_invocation is unnecessary. According to the type definition for _EvalMetricResultWithInvocation, actual_invocation is a required field and not optional. This check is confusing and should be removed to align with the type definitions.

Suggested change
"actual_response": AgentEvaluator._convert_content_to_text(
per_invocation_result.actual_invocation.final_response
),
) if per_invocation_result.actual_invocation else None,
"actual_response": AgentEvaluator._convert_content_to_text(
per_invocation_result.actual_invocation.final_response
),

Comment on lines 451 to 453
"actual_tool_calls": AgentEvaluator._convert_tool_calls_to_text(
per_invocation_result.actual_invocation.intermediate_data
),
) if per_invocation_result.actual_invocation else None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to actual_response, the null check for actual_invocation here is unnecessary because actual_invocation is a required, non-optional field.

Suggested change
"actual_tool_calls": AgentEvaluator._convert_tool_calls_to_text(
per_invocation_result.actual_invocation.intermediate_data
),
) if per_invocation_result.actual_invocation else None,
"actual_tool_calls": AgentEvaluator._convert_tool_calls_to_text(
per_invocation_result.actual_invocation.intermediate_data
),

@morganroux morganroux changed the title fix: handle expected_invocation gracefully fix: _EvalMetricResultWithInvocation handle expected_invocation gracefully Mar 1, 2026
@morganroux morganroux changed the title fix: _EvalMetricResultWithInvocation handle expected_invocation gracefully fix: _EvalMetricResultWithInvocation handles expected_invocation gracefully Mar 1, 2026
@morganroux morganroux marked this pull request as ready for review March 1, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eval [Component] This issue is related to evaluation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_EvalMetricResultWithInvocation fails with conversation_scenario (user simulation) - expected_invocation is None

2 participants