arcade-mcp/libs/arcade-evals/arcade_evals/_evalsuite/_comparative.py
jottakka 7472b18106
Fixing bug with multiple providers + stats for multiple runs (#752)
@EricGustin you can use this cli command:
```
uv run arcade evals mcp_building_evals_results/eval_toolkit_iteration_dict.py \
    -p openai:gpt-4o,gpt-4o-mini \
    -p anthropic:claude-sonnet-4-20250514 \
    -k openai:$OPENAI_API_KEY \
    -k anthropic:$ANTHROPIC_API_KEY \
    -d \
    --num-runs 3 \
    --seed random \
    --multi-run-pass-rule majority \
    --max-concurrent 6 \
    -o mcp_building_evals_results/results

```

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Touches core eval execution and all result formatters while adding new
CLI inputs and output schema (`run_stats`/`critic_stats` and capture
`runs`), so regressions could affect evaluation results and report
compatibility despite being additive and validated.
> 
> **Overview**
> Adds **multi-run evaluation support** to `arcade evals` via new flags
`--num-runs`, `--seed`, and `--multi-run-pass-rule`, with upfront
validation and plumbing through the CLI runner into eval/capture suite
execution.
> 
> Fixes provider selection UX/bug by making `--use-provider/-p`
**repeatable** (instead of a space-delimited string), updates
docs/examples accordingly, and extends capture mode to optionally record
**per-run tool calls** (`CapturedRun`) when `num_runs > 1`.
> 
> Enhances all output formatters (HTML/Markdown/Text/JSON) to
**propagate and display** per-case `run_stats` and `critic_stats`,
including new HTML UI for run tabs/cards and comparative tables showing
mean ± stddev when multi-run data is present.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
2ee1654b7d1fbb9538373507355636164b16a066. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
2026-02-09 14:25:28 -03:00

133 lines
3.9 KiB
Python

"""Comparative case builder for multi-track evaluations.
Provides a fluent API for defining evaluation cases that run against
multiple tool tracks with track-specific expected results and critics.
"""
from __future__ import annotations
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any
from arcade_evals._evalsuite._types import (
ComparativeCase,
EvalRubric,
ExpectedMCPToolCall,
ExpectedToolCall,
)
if TYPE_CHECKING:
from arcade_evals.critic import Critic
class ComparativeCaseBuilder:
"""Fluent builder for creating comparative cases.
Example:
builder = ComparativeCaseBuilder(
suite=suite,
name="weather_query",
user_message="What's the weather?",
)
builder.for_track(
"Google Weather",
expected_tool_calls=[...],
critics=[...],
).for_track(
"OpenWeather",
expected_tool_calls=[...],
critics=[...],
)
"""
def __init__(
self,
suite: Any, # EvalSuite - avoid circular import
name: str,
user_message: str,
system_message: str = "",
additional_messages: list[dict[str, Any]] | None = None,
rubric: EvalRubric | None = None,
) -> None:
"""Initialize the builder.
Args:
suite: The parent EvalSuite.
name: Unique case name.
user_message: User message (shared across tracks).
system_message: System message (shared across tracks).
additional_messages: Additional context (shared).
rubric: Default rubric (shared, can be overridden).
"""
self._suite = suite
self._case = ComparativeCase(
name=name,
user_message=user_message,
system_message=system_message,
additional_messages=additional_messages or [],
rubric=rubric,
)
def for_track(
self,
track_name: str,
expected_tool_calls: Sequence[ExpectedToolCall | ExpectedMCPToolCall],
critics: list[Critic] | None = None,
) -> ComparativeCaseBuilder:
"""Add track-specific configuration.
Args:
track_name: The track name (must be registered via add_*_tools).
expected_tool_calls: Expected tool calls for this track.
critics: Critics for this track.
Returns:
Self for method chaining.
Raises:
ValueError: If track doesn't exist.
"""
# Validate track exists
if not self._suite._track_manager.has_track(track_name):
available = self._suite._track_manager.get_track_names()
raise ValueError(
f"Track '{track_name}' not found. "
f"Available tracks: {available}. "
f"Register tracks first using add_*_tools(track=...)."
)
self._case.add_track_config(
track_name=track_name,
expected_tool_calls=expected_tool_calls,
critics=critics,
)
return self
def build(self) -> ComparativeCase:
"""Build and return the comparative case.
Returns:
The configured ComparativeCase.
Raises:
ValueError: If no tracks configured.
"""
if not self._case.track_configs:
raise ValueError(
f"No tracks configured for comparative case '{self._case.name}'. "
f"Use .for_track() to add at least one track configuration."
)
return self._case
@property
def case(self) -> ComparativeCase:
"""Access the underlying case for inspection.
Note: This is primarily for testing. The case may be incomplete
if tracks haven't been configured yet. Use build() to validate
and finalize the case.
Returns:
The ComparativeCase (may be incomplete).
"""
return self._case