跪拜 Guibai
← All articles
Agent · LLM

Agent Harness I7: Event Streams, Span Trees, and pass^k for Reproducible Evaluations

By cheerfunfun ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

One lucky pass hides a 50% failure rate; treating a single run as a metric is how flaky agents ship. I7 gives harnesses the same CI discipline as unit tests: confidence intervals, regression gates, and a replayable trace, so a tool that fails intermittently becomes a gate that fails the build instead of a surprise in production.

Summary

I7 builds on the event stream already defined in I1–I6 and turns single runs into reproducible readings. Events are the only source of truth: every metric must trace back to an event. Spans are generated from runtime nesting, named after OpenTelemetry GenAI conventions, and metrics count only what the events support - turns, tool attempts, retries, tool errors, compactions, stop reason, usage. The transcript is JSONL, one event per line, preserving timestamps so it can be replayed by any evaluator.

Fixtures are deterministic: a task, scripted model responses, an executor factory that takes a trial number to inject per-run failures, and assertions. The suite runs each case k times and reports pass^k, the fraction of cases where all k runs pass, with a Wilson 95% confidence interval. A regression gate compares the current result to a baseline that stores the suite hash, repeats, and per-case pass rates; any drop or a changed hash rejects the run, distinguishing code regression from evaluation drift.

Verification shows a flaky tool passing 2 out of 4 runs, which a single run would miss. The migration path adds events at run boundaries, consumes them with build_spans and collect_metrics, writes 3-5 fixtures, and stores a baseline for CI. Boundaries are explicit: fixtures are not online distributions, pass^k is an estimate, judges must be independent of the generator to avoid reward hacking, and request bodies stay out of the event stream to keep traces deterministic and diffable.

Takeaways
— Events are the only source of truth; every metric must trace back to an event or it's defined but not wired.
— Spans follow runtime nesting (run to turn to model/context/tool) and align with OpenTelemetry GenAI naming.
— Metrics count only what events support: turns, tool_attempts, retries, tool_errors, compactions, stop_reason, usage; no subjective quality.
— A fixture is a task, scripted model responses, an executor factory that takes a trial number to inject failures, and assertions; pass^k requires all k runs to pass, with Wilson 95% CI.
— The regression gate compares the current report to a baseline that stores the suite hash, repeats, and per-case pass rates; a drop or hash change rejects.
— Migration adds events at run boundaries, then uses build_spans and collect_metrics, writes 3-5 fixtures, stores a baseline, and compares passed in CI; transcript gets masked.
— Acceptance criteria: deleting an event must reduce a metric; changing an assertion must identify the failed case; otherwise the observation layer is just logs.
Conclusions

The example of a flaky tool returning 42 on 503 shows why a single run is a misleading sample: the harness records completed even when the tool fails intermittently, so only repeated runs with pass^k expose the real 50% failure rate.

By requiring every metric to be derivable from the event stream, the design blocks vanity metrics that look good on a dashboard but have no path to production; it forces instrumentation to be the actual source of truth.

The warning about LLM-as-judge is not new, but tying it to the closed-loop of using the same model to score and then update prompts makes it concrete: the loop collapses toward the model's own bias, and the regression gate can't see it because the metric itself is contaminated.

Concepts & terms
span
A measurable unit of work in a run, carrying parent-child relationships; run is the root, turns and tool calls hang under it.
transcript
The event stream saved as JSONL, one event per line, preserving timestamp, turn, type, and data so a run can be replayed.
fixture
A deterministic evaluation case with a fixed task, scripted model responses, an executor factory, and assertions; used to test pass^k.
pass^k
A metric where a case passes only if all k runs pass; suite pass^k is the fraction of such cases, with a Wilson confidence interval.
Wilson interval
A confidence interval for binomial proportions that works well with small samples; 0/1 and 1/1 still have wide intervals.
evaluation set hash
A stable digest of fixture definitions; if the hash changes, the baseline must be rebuilt to avoid confusing drift with regression.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗