adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

final_response_match_v2 silently ignores `include_intermediate_responses_in_final` criterion flag

Open darshil3011 opened this issue 6 months ago • 0 comments

🔴 Required Information

Is your feature request related to a specific problem?

PR #5316 (closing #5217) added include_intermediate_responses_in_final to BaseCriterion so every criterion subclass inherits it, and extended get_text_from_content() in llm_as_judge_utils.py to honor the flag when given an Invocation. The flag was then wired into rubric_based_final_response_quality_v1.

final_response_match_v2 has the same class of bug as #5217, but the fix from #5316 does not reach it. In final_response_match_v2.py:

# src/google/adk/evaluation/final_response_match_v2.py:162-163
reference = get_text_from_content(expected_invocation.final_response)
response  = get_text_from_content(actual_invocation.final_response)

The evaluator passes .final_response (a Content), not the full Invocation. So even when the user sets include_intermediate_responses_in_final: true on an LlmAsAJudgeCriterion, the V2 evaluator silently drops all pre-tool-call text — the criterion flag has no effect.

This is a sister-evaluator gap with rubric_based_final_response_quality_v1, where the same flag does work as advertised after #5316.

Describe the Solution You'd Like

Wire the existing BaseCriterion.include_intermediate_responses_in_final flag through FinalResponseMatchV2Evaluator.format_auto_rater_prompt(). Pass the full Invocation (not just .final_response) to get_text_from_content(), which already supports the flag after #5316.

Impact on your work

We are building agent layers on top of our video analytics stack — agents that observe a scene (text), call an analyzer tool, then synthesize a conclusion (more text). Our golden responses for eval come from human analysts and contain the full reasoning chain. We are migrating from rubric_based_final_response_quality_v1 to final_response_match_v2 for stricter pass/fail scoring against these goldens, and hit this gap immediately: the V2 evaluator only sees the post-tool synthesis, so any ground truth responses whose narrative starts with scene observation marks as INVALID.

Not blocking, but it forces us to choose between the V2 scoring model and the full-response semantics that #5316 already approved for V1.

Willingness to contribute

Yes. The fix is ~10–20 LOC mirroring the wiring pattern from #5316 plus unit tests covering the flag-on / flag-off paths against an invocation that has intermediate invocation_events.


🟡 Recommended Information

Describe Alternatives You've Considered

  1. Sticking with rubric_based_final_response_quality_v1 (which already honors the flag). Doesn't give us strict pass/fail majority-vote semantics.
  2. Pre-flattening invocations before evaluation by collapsing intermediate_data.invocation_events text into final_response ourselves. Works, but defeats the purpose of having a documented criterion flag, and duplicates logic that already exists in get_text_from_content().

Proposed API / Implementation

# src/google/adk/evaluation/final_response_match_v2.py
@override
def format_auto_rater_prompt(
    self,
    actual_invocation: Invocation,
    expected_invocation: Optional[Invocation],
) -> str:
    if expected_invocation is None:
        raise ValueError("expected_invocation is required for this metric.")

    include_intermediate = self._criterion.include_intermediate_responses_in_final
    reference = get_text_from_content(
        expected_invocation,
        include_intermediate_responses_in_final=include_intermediate,
    )
    response = get_text_from_content(
        actual_invocation,
        include_intermediate_responses_in_final=include_intermediate,
    )
    user_prompt = get_text_from_content(expected_invocation.user_content)
    return self._auto_rater_prompt_template.format(
        prompt=user_prompt,
        response=response,
        golden_response=reference,
    )

No new fields, no schema migration — purely a wiring fix that activates an existing criterion flag for one more evaluator.

Additional Context

  • Originating fix that established the pattern: PR #5316 / closed #5217
  • Field definition: src/google/adk/evaluation/eval_metrics.py:118-129
  • Helper that already supports the flag: src/google/adk/evaluation/llm_as_judge_utils.py:48-79
  • Gap location: src/google/adk/evaluation/final_response_match_v2.py:162-163

darshil3011 avatar May 13 '26 19:05 darshil3011