Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ All notable changes to SkillEvaluator are documented in this file.

### Added

- Tier 3 reports show token usage per case, per agent and over all agents, as
a measurement that is not scored. The JSON payload gains `token_usage`;
`BENCHMARK.md` gains a **Token Usage** section; the Markdown report, the HTML
report (under Measured Agent Resources), `validate --verbose` and
`tier3 evaluate --verbose` show the same numbers. Cached tokens are part of
the prompt and are not added again. Attempts that failed before scoring count
as usage. Missing counters leave a partial total and are never estimated.
The with-skill change needs complete counts for the same attempts in both
arms, and both arms must have succeeded. Token usage never displaces score
evidence: it joins the report payload last, and its case rows, then its sums,
are left out, with a note, when the payload would pass its size or node
limits, also after the run's next steps, `tier3 evaluate`'s case findings and
`validate`'s applicability fields join it. A baseline that did not run is
shown as not run, and a reused baseline's tokens are marked as used in the
run it came from.

- Capability-gated CI onboarding for protected Tier 1 `--llm`/SkillSpector
checks, independent Tier 3 gateway/judge settings and native agent models.
Combined reports retain source-bound `BENCHMARK.md` cards for every outcome;
Expand Down Expand Up @@ -499,6 +515,23 @@ All notable changes to SkillEvaluator are documented in this file.
leaves its arm's LLM and tool totals `N/A` (`null` in JSON). Native ATIF
timing is unchanged.

- Tier 3 reports no longer say `baseline not run` for an agent whose baseline
arm ran but failed, for example after one baseline attempt hit the agent
timeout. `BENCHMARK.md` now shows that agent's with-skill scores as
`90.0% — baseline incomplete (1 of 2 attempts scored); uplift unavailable`,
or `baseline unavailable` when no baseline attempt scored, and keeps
`baseline not run` for a skipped baseline. An **Agent coverage** list under
the score table names each failed arm, including a failed with-skill arm,
with its scored and expected attempts and the first Harbor exception type in
words, such as `agent timeout error`; the Tier 3 row of the tier status
table names the agent and arm. The JSON payload records the same facts in
`coverage_notices`, which the HTML report shows under
**Agent coverage notes** and the full terminal report
(`validate --verbose` or `-r cli`) prints in the Tier 3 block, also when
Tier 3 is non-blocking. The compact default `validate` view leaves them to
the HTML and JSON reports and `BENCHMARK.md`. A failed arm still fails the
agent and the run, and the notes say so.

- Tier 3 standard judges under `LLM_JUDGE_RETRY_POLICY=strict` with Bedrock
as the provider no longer label a Bedrock error that the policy treats as an
unavailable model, such as throttling, a missing or inaccessible model, or
Expand Down
123 changes: 120 additions & 3 deletions docs/reports.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -924,9 +924,11 @@ Score, and publication eligibility.

When the HTML report has no lift for an agent or dimension, its label says
why. **no baseline** means that row has no baseline score, for example after
`--skip-baseline`. **comparison unavailable** means a baseline score was
recorded but cannot be compared with the with-skill score, for example because
the arms used different score policies or no case kept matching judge models.
`--skip-baseline`, or after a baseline arm that ran but failed; the
**Agent coverage notes** described below tell the two apart.
**comparison unavailable** means a baseline score was recorded but cannot be
compared with the with-skill score, for example because the arms used
different score policies or no case kept matching judge models.

For each LLM metric (`accuracy`, `goal_accuracy`, and `behavior_check`), cases
that used different judge models across the arms are excluded from that
Expand Down Expand Up @@ -958,6 +960,47 @@ count as activation opportunities; missing or unsupported evidence remains
unknown. Eligibility is determined separately for each agent, so another
agent with observed activation can still contribute a comparison.

An arm that ran but failed, for example because one baseline attempt hit the
agent timeout, fails the agent and the run, and the other arm keeps its
scores. Reports describe such an arm by how many of its attempts scored,
never as not run. In `BENCHMARK.md`, the agent's Overall and dimension cells
read `90.0% — baseline incomplete (1 of 2 attempts scored); uplift unavailable`, or
`baseline unavailable` when no baseline attempt scored. They read
`baseline failed (2 of 2 attempts scored)` when the arm failed with no attempt
missing, and `baseline failed` with no counts when its recorded counts are
unusable. A baseline skipped with `--skip-baseline` still reads
`baseline not run`. An **Agent coverage** list under the table names each
failed arm, how many of its attempts scored, and the first Harbor exception
type it recorded, in words such as `agent timeout error`. When the agent is
marked failed, the entry also says that the agent and the Tier 3 run are
marked failed. The Tier 3 row of the tier status table names the agent and
arm.

The canonical JSON payload lists the same facts in `coverage_notices`, one
entry per failed arm:

- `code`: `baseline_failed` or `with_skill_failed`, the arm whose recorded
status is `failed`.
- `agent` and `condition` (`without_skill` or `with_skill`).
- `state`: `incomplete` when some attempts scored, `unavailable` when none
scored, or `failed` when no attempt is missing or the counts are unusable.
- `scored_attempts` and `expected_attempts`: `null`, with `state` `failed`,
when the arm's counters are missing or inconsistent, for example more scored
than expected attempts, or no expected attempts after a job failure.
- `failure`: the first Harbor exception type in words, or `null`.
- `message`: the sentence the reports show.

The HTML report lists each message under **Agent coverage notes** at the top
of the Tier 3 section. Its agent details label an agent whose baseline arm
failed the way they label a skipped baseline, for example **no baseline** and
`baseline N/A`, so the callout is what tells the two apart. The full terminal
report, from `validate --verbose` or an explicit `-r cli`, prints the notes
under **Agent coverage notes** in the Tier 3 block, also when Tier 3 is
non-blocking (the default). The compact default view of `validate` does not
print them and leaves them to the HTML and JSON reports and `BENCHMARK.md`.
`tier3 evaluate` lists each agent's failed condition with its errors, as
before.

### Measured agent resources

Each agent's canonical JSON payload contains a `resources` object. The HTML
Expand Down Expand Up @@ -1007,6 +1050,80 @@ Missing timing stays `N/A` (`null` in JSON), never zero, and follows the same
complete-arm and matching-case rules as tokens. Timing is diagnostic and does
not change scores, verdicts, or gates.

### Token usage

The canonical JSON payload also carries a `token_usage` object when at least
one attempt recorded token counts and the report limits leave room for it (see
below). It sums the agent's own tokens per case, per
agent arm, and over all agents, and says how many attempts each sum covers. It
is a measurement: it is not scored and changes no metric, dimension, verdict,
or gate.

- Tokens are prompt plus completion (`total_tokens`). Prompt counts include
cached tokens, so cached tokens are never added again;
`uncached_prompt_tokens` is prompt minus cached. A missing cache counter
counts as 0.
- Attempts that failed before scoring, such as an attempt that hit the agent
timeout, still used tokens and are counted. So are the scored attempts of an
arm that failed. `coverage.unscored_attempts` counts the attempts without a
score. Such an attempt belongs to the case whose task directory its Harbor
`result.json` or `config.json` names, or else to the case its trial name
starts with. `resources` keeps its own totals, which need every attempt of an
arm scored and measured.
- Nothing is estimated. An attempt with a missing or invalid counter adds no
tokens. Its arm's `coverage.status` is then `partial` (other attempts were
measured) or `unavailable` (none were), and the totals cover only the measured
attempts. An arm that did not run is `not_run`, and its `totals` are `null`:
a skipped arm, or an arm without attempts that the agent has no record of or
that the payload `mode` leaves out (`with_skill_only` or `baseline_only`).
The score tables show such a baseline as not run. A sum above
9,007,199,254,740,991 (`2^53 - 1`), the largest integer JSON keeps exact, is
`unavailable` with `total_out_of_range` and `null` totals.
- `coverage` also gives `expected_attempts`, `observed_attempts`,
`measured_attempts`, and `reason_codes` such as `missing_token_counters`,
`invalid_token_counters`, and `missing_attempts`.
- `delta.total_tokens` is with skill minus baseline, and
`delta.total_tokens_change_percent` divides it by the baseline. A change needs
complete counts in both arms for the same cases and attempts, and both arms
must have succeeded, because the report withholds the scores of any other arm.
Otherwise `delta.status` is `unavailable` and `delta.reason_codes` and
`delta.reason` say why, for example `baseline_not_run`, `baseline_failed`,
`baseline_status_unknown` (the arm ran attempts without a recognized run
status), `baseline_tokens_incomplete`, `baseline_total_out_of_range`,
`case_scope_mismatch` (both arms ran attempts, for different cases or
numbers of attempts per case), or `agent_scope_mismatch` for the sum over all
agents.
- A run that reused an earlier run's baseline
(`tier3 evaluate --reuse-baseline`) has `baseline_reused: true`. Its baseline
counts come from the trajectories copied from that run: they are the tokens
the baseline used there, not tokens used in this run, and every token usage
table says so.

Token usage joins the payload after the report size budget, so it never
displaces trials or other score evidence. It also never pushes the payload past
the embedded size budget or the report limits that every report checks, such as
100,000 JSON values, including after the run's next steps, the case findings
that `tier3 evaluate` adds and `validate`'s applicability fields join it. When
it does not fit, its case rows go first: `token_usage.case_rows_omitted` and
`report_truncation.omitted.token_usage_case_rows` count them, and every report
says so. If the agent sums do not fit either, `token_usage` is left out and
`report_truncation.omitted.token_usage` is 1. If the payload cannot carry even
that record, for example because it exceeds the report limits without token
usage, `token_usage` is left out without a record, and every report marks the
payload as it would without token usage.

`BENCHMARK.md` has a **Token Usage** section after Results at a Glance: one row
per agent and one for all agents, with the case rows in a collapsed table that
shows the first 50 case rows. The Markdown report has the same table under its
Tier 3 section. The HTML report lists the case rows under **Measured Agent
Resources**, at most 64 per agent, read from the full Tier 3 data rather than
its bounded preview. Each table says how many more case rows are in the JSON
payload. The full terminal report (`validate --verbose` or `-r cli`) and
`tier3 evaluate --verbose` print the agent rows only and name the files that
hold the case rows: the HTML, Markdown and JSON reports for `validate`, and
`report.html` and `tier3-benchmark.md` in the run directory for
`tier3 evaluate`.

### Failure reasons and per-trial rows

Each evaluator card lists its per-trial evidence by eval case with the
Expand Down
4 changes: 4 additions & 0 deletions src/skillevaluator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,10 @@ def _on_case_rows(rows: list[TierRow]) -> None:
agent_eval_payload.setdefault("applicability", "required")
agent_eval_payload.setdefault("reason_code", "tier3_source_present")
agent_eval_payload.setdefault("source_kind", source_kind)
from skillevaluator.evaluation.tier3_report import fit_token_usage

# Measured token usage makes room for these keys when the payload is at its limits.
fit_token_usage(agent_eval_payload)
tier3_result.metadata["gating"] = {"tier": 3, "blocking": block_on_agent_eval_effective}

# Reporters and the exit gate consume the same finalized result objects.
Expand Down
117 changes: 117 additions & 0 deletions src/skillevaluator/evaluation/tier3_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ def render_agent_eval_html_report(
canonical_payload = result.metadata.get("agent_eval")
if isinstance(canonical_payload, dict):
_apply_case_findings(canonical_payload, engine_result, run_dir, skill_path, use_llm=use_llm_judge)
# The case findings joined after the size budget; token usage makes room for them.
fit_token_usage(canonical_payload)
if engine_result is not None and isinstance(canonical_payload, dict):
# Persist only the compact feedback contract needed by the CLI. The
# complete canonical payload remains in the HTML report and can be much
Expand All @@ -648,6 +650,13 @@ def render_agent_eval_html_report(
"schema_version": _TIER3_FEEDBACK_SCHEMA_VERSION,
**{field: list(canonical_payload.get(field) or []) for field in _TIER3_FEEDBACK_FIELDS},
}
from skillevaluator.tier3.token_usage import per_agent_token_usage

# The terminal summary prints token usage per agent; per-case rows stay in the report files.
if token_usage := per_agent_token_usage(canonical_payload.get("token_usage")):
engine_result["token_usage"] = token_usage
else:
engine_result.pop("token_usage", None)

target = output_path.expanduser().resolve() if output_path is not None else run_dir / "report.html"
from skillevaluator.publication_identity import publication_target_name
Expand Down Expand Up @@ -1125,6 +1134,27 @@ def build_agent_eval_payload(
payload["case_selection"] = dict(case_selection)
if harbor_summary:
payload["harbor_viewer"] = harbor_summary
from skillevaluator.reporting.tier3_coverage import coverage_notices

# Name each arm that ran but failed, so no report reads its missing scores
# as an arm that never ran.
if notices := coverage_notices(agent_payloads):
payload["coverage_notices"] = notices
from skillevaluator.tier3.token_usage import USAGE_ONLY_ATTEMPT_KEYS, build_token_usage

# Measured, never scored: token usage per case and agent, counting attempts
# that failed before scoring. Scores and ``resources`` do not read it. It
# joins the payload after the budget, so it never displaces score evidence.
baseline_record = (run_config or {}).get("baseline")
token_usage = build_token_usage(
{
name: {**agent, **{key: agents.get(name, {}).get(key) for key in USAGE_ONLY_ATTEMPT_KEYS}}
for name, agent in agent_payloads.items()
},
mode=mode,
# A reused baseline's copied trajectories hold the tokens of the run it came from.
baseline_reused=isinstance(baseline_record, dict) and baseline_record.get("mode") == "reused",
)

_layer_llm_insights(
payload,
Expand Down Expand Up @@ -1156,6 +1186,10 @@ def build_agent_eval_payload(
)
payload = _sanitize_json_numbers(payload)
_enforce_report_payload_budget(payload, report_budget, enforce_size=enforce_embedded_size)
if token_usage:
payload["token_usage"] = _sanitize_json_numbers(token_usage)
if enforce_embedded_size:
fit_token_usage(payload)
return payload


Expand Down Expand Up @@ -1594,6 +1628,89 @@ def refresh_signal() -> None:
refresh_signal()


# ``report_truncation.omitted`` keys that only token usage adds.
_TOKEN_USAGE_OMISSIONS = ("token_usage", "token_usage_case_rows")


def fit_token_usage(payload: dict[str, Any]) -> None:
"""Keep measured token usage from costing a bounded payload its report limits.

Token usage is unscored, so it may never push a payload past the embedded
size budget or make it fail the report serialization limits (nodes, depth
and text) that every reporter checks. It joins the payload last, after the
size budget, so it gives way first: its per-case rows, then its sums, each
drop recorded in ``report_truncation``. If not even that record fits, the
token usage and its records go, which leaves the payload as it is without
token usage. Code that adds fields to a built payload, such as case findings
or ``validate``'s applicability keys, calls this again.
"""
omitted = _report_omissions(payload)
if "token_usage" not in payload and not (omitted and any(key in omitted for key in _TOKEN_USAGE_OMISSIONS)):
return
if _token_usage_fits(payload):
return
if "token_usage" in payload:
from skillevaluator.tier3.token_usage import drop_token_usage_cases

dropped = drop_token_usage_cases(payload["token_usage"])
if (
dropped
and _record_token_usage_omission(payload, "token_usage_case_rows", dropped)
and _token_usage_fits(payload)
):
return
del payload["token_usage"]
if _record_token_usage_omission(payload, "token_usage", 1) and _token_usage_fits(payload):
return
_remove_token_usage_omissions(payload)


def _report_omissions(payload: dict[str, Any]) -> dict[str, Any] | None:
truncation = payload.get("report_truncation")
omitted = truncation.get("omitted") if isinstance(truncation, dict) else None
return omitted if isinstance(omitted, dict) else None


def _token_usage_fits(payload: dict[str, Any]) -> bool:
from skillevaluator.reporting.base import agent_eval_report_serialization_issue

# The minimal last-resort payload carries no details.
if "payload_sections" in (_report_omissions(payload) or {}):
return False
try:
size = _serialized_payload_size(payload)
except (TypeError, ValueError):
return False
return size <= _MAX_EMBEDDED_REPORT_BYTES and agent_eval_report_serialization_issue(payload) is None


def _record_token_usage_omission(payload: dict[str, Any], section: str, count: int) -> bool:
"""Count a token usage drop in ``report_truncation``; ``False`` when its record cannot take it."""
if "report_truncation" not in payload:
payload["report_truncation"] = _ReportBudget(omitted={section: count}).signal()
return True
omitted = _report_omissions(payload)
if omitted is None:
return False
previous = omitted.get(section)
total = count + (previous if isinstance(previous, int) and not isinstance(previous, bool) else 0)
payload["report_truncation"]["omitted"] = dict(sorted({**omitted, section: total}.items()))
return True


def _remove_token_usage_omissions(payload: dict[str, Any]) -> None:
"""Take token usage's keys out of ``report_truncation``, and the record when only they made it."""
omitted = _report_omissions(payload)
if omitted is None or not any(key in omitted for key in _TOKEN_USAGE_OMISSIONS):
return
remaining = {key: value for key, value in omitted.items() if key not in _TOKEN_USAGE_OMISSIONS}
truncation = payload["report_truncation"]
if remaining or truncation.get("artifact_loading"):
truncation["omitted"] = remaining
else:
del payload["report_truncation"]


def _serialized_payload_size(payload: dict[str, Any]) -> int:
return len(json.dumps(payload, ensure_ascii=False, separators=(",", ":"), allow_nan=False).encode("utf-8"))

Expand Down
Loading
Loading