Skip to content

feat(eval): provide preceding conversation context for rubric evaluat… - #283

Open
sowndappan5 wants to merge 1 commit into
agentevals-dev:mainfrom
sowndappan5:feat/turn-preceding-rubric-context
Open

sowndappan5 wants to merge 1 commit into
agentevals-dev:mainfrom
sowndappan5:feat/turn-preceding-rubric-context

Conversation

@sowndappan5

Copy link
Copy Markdown

Summary:

This PR Fixes #253.

When evaluating a multi turn conversation with rubric_based_final_response_quality_v1, turns were evaluated in complete isolation. As a result, when an assistant response in later turn (ex: Turn 2) relied on facts, preferences or corrections from an earlier turn (ex: Turn 1) the LLM judge treated those earlier details as unsupported or failed to verify that the latest preference was honored. This PR adds preceding conversation context (turns 0..i-1) to turn i's judge prompt while strictly excluding future turns (i+1...) to prevent leakage.

Problem & Reproduction

  1. Reproduction:
    In a multi-turn flow:
    • Turn 1: User requests a booking in Paris for Monday and assistant asks for room type and nights.
    • Turn 2: User provides details and changes the day to Tuesday and assistant confirms Paris booking on Tuesday.
  2. Current behavior:
    The judge prompt for Turn 2 only contained <user_prompt> for Turn 2 because "Paris" and original "Monday" were absent from Turn 2's prompt and the judge marked "Paris" as ungrounded/unsupported evidence and returned Verdict: no.

Changes I made

  1. src/agentevals/judges.py:

    • Added format_preceding_dialogue(invocations): formats preceding turns (0..i-1) into readable context including user prompts, assistant replies and intermediate tool calls.
    • Added _RUBRIC_FINAL_RESPONSE_WITH_HISTORY_PROMPT: updates the evaluation preamble and template to include <preceding_conversation> as trusted evidence alongside <user_prompt> and <response_steps>.
    • Added RubricBasedFinalResponseQualityV1WithHistory: overrides evaluate_invocations to map each invocation to its preceding slice (actual_invocations[:i]) and injects it into format_auto_rater_prompt, cleaning up after evaluation.
  2. src/agentevals/builtin_metrics.py:

    • Registered rubric_based_final_response_quality_v1 in _DIRECT_EVALUATORS to route to RubricBasedFinalResponseQualityV1WithHistory.
  3. tests/test_rubrics.py:

    • Added TestPrecedingConversationContext with tests verifying:
      • Preceding turns are present in Turn 2's prompt.
      • Future turns are never leaked into Turn 1 (Turn 1 prompt contains "None (this is the first turn).").
      • Empty conversations and tool interactions in preceding turns format properly.

Testing & Verification

All checks and tests pass locally:

  • Linter check:
    uv run ruff check src/agentevals/judges.py src/agentevals/builtin_metrics.py tests/test_rubrics.py
    #All checks passed!
  • Rubrics test suite:
    uv run pytest tests/test_rubrics.py -q
    #31 passed in 3.91s (all 29 existing test+2 new regression test)
  • Layering check:
    uv run pytest tests/test_layering.py -q
    #2 passed in 0.24s
  • Core evaluation test suite:
    uv run pytest tests/test_rubrics.py tests/test_builtin_metrics.py tests/test_adk_bridge.py tests/test_runner.py -q
    #102 passed in 15.00s

Checklist

  • Tests added and updated
  • All tests pass (uv run pytest)
  • Documentation updated (if applicable)
  • Commits are clean with meaningful messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide preceding conversation context when grading a selected turn

1 participant