Ab Equivalence
ASecurityCompare two versions of an LLM-directed document - an original (teacher) and a candidate (student) - across a transfer set and return a per-case behavioural-equivalence verdict plus an efficiency signal. A transform-agnostic library capability other skills compose to gate a transform on behavioural sameness. TRIGGER when asked to A/B test two versions of a prompt / instruction / skill, to check whether a rewritten or compressed document still behaves the same as the original, to validate beha...
- 37 stars
- 0 votes
- 0 copies
- 3 views
- Added August 31, 2026
Works with
Security analysis
100/100Pro scans all 4 files and shows the line behind each finding
npx -y skills add bjcoombs/ai-native-toolkit --skill ab-equivalence --agent claude-codeAre you the author of Ab Equivalence?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/bjcoombs-ab-equivalence)---
name: ab-equivalence
description: "Compare two versions of an LLM-directed document - an original (teacher) and a candidate (student) - across a transfer set and return a per-case behavioural-equivalence verdict plus an efficiency signal. A transform-agnostic library capability other skills compose to gate a transform on behavioural sameness. TRIGGER when asked to A/B test two versions of a prompt / instruction / skill, to check whether a rewritten or compressed document still behaves the same as the original, to validate behavioural equivalence between two document versions, to gate a transform on no-regression, or when a skill needs the run-the-runner-on-both-versions-and-judge-equivalence capability."
---
# A/B equivalence - a transform-agnostic behavioural-equivalence capability
A thin capability that compares two versions of an LLM-directed document - an `original` (the teacher) and a `candidate` (the student) - across a transfer set, and returns a per-case verdict on whether the candidate still induces the behaviour the original induced. Each version runs several times beside a control (a copy of the original), a blind judge marks the transcripts, and `scripts/ab_aggregate.py` counts a loss only when it outlasts the control's noise.
It is **transform-agnostic**: it judges *behavioural equivalence between two versions* and neither knows nor cares which transform produced the candidate. It therefore serves every optimizer transform that claims to preserve behaviour - compression today, directive-clarity next - not just compression. It is a **library capability** other skills compose: `semantic-compress` invokes it to gate a distillation, and `skill-forge` exposes it alongside its own quality gate. It does **not** judge *absolute quality* ("is this skill good?") - that is a different question answered by different judges. A/B equivalence judges *sameness between two versions* ("does the candidate still do what the original did?").
This skill **owns the runner** (`references/runner-prompt.md`, the pure-wrapper template, paths relative to this skill directory). The runner is the shared execution primitive: it applies one version of a document to one case input and returns a transcript and self-report. Skills that need behavioural comparison compose this capability rather than re-implementing the runner.
The runner ships in **two variants**, both pure wrappers returning the same six self-report fields (see `references/runner-prompt.md`):
- the **skill variant** (default) - the document is invoked on demand against a case input;
- the **instruction-file variant** - the document is an *always-loaded* agent instruction file (`CLAUDE.md`, `AGENTS.md`, `GEMINI.md`, `.cursor/rules/*`, `.github/copilot-instructions.md`); the runner is handed only that file as its operating context plus a realistic repo task, and runs **read-only / sandboxed** (it states the actions it would take, never mutating the repo).
The variant is the caller's choice (skill-forge's artifact-type detection selects it); both produce a transcript the equivalence judge and skill-forge's lenses read identically.
## Input contract
| Input | Required | Notes |
|-------|----------|-------|
| `original` | yes | Path to the teacher document - the version whose behaviour is the equivalence target. |
| `candidate` | yes | Path to the student document - the transformed version under test. |
| `transfer_set` | yes | Array of cases spanning the test taxonomy (happy / edge / adversarial / composition). The transfer set *is* the operational definition of the behaviour being preserved, so its breadth bounds the safety of the conclusion. |
| `repeats` | no | Runs per version per case, `k`. Default 3, minimum 2. The caller sets it: runner cost per case is `3k` on the first round and `k` on later rounds. |
The caller (e.g. `semantic-compress`) owns deriving and confirming the transfer set; this capability consumes it. A thin transfer set yields a weak equivalence claim - the caller is responsible for flagging coverage, and the output records it.
## Mechanism
A single run per version cannot tell a lost behaviour from runner-to-runner variation: a runner on a long document leaves a different detail out each time, so one original run against one candidate run reads "regressed" even when the two documents are identical. On the #1764 split, an unchanged copy compared with the original that way read `candidate-regressed` in 4 of 6 cases. The method therefore runs each version several times, runs a **control** (a byte-identical copy of the original) the same way, judges blind, and counts a loss only when it outlasts the control's noise.
The script is `skills/ab-equivalence/scripts/ab_aggregate.py` from the plugin root; when this skill is loaded, `${CLAUDE_SKILL_DIR}` resolves to its directory. A caller that reads this file without loading the skill uses the plugin-root path.
For each case in the transfer set:
1. **Run each version `k` times.** Run the runner (`references/runner-prompt.md`, the pure-wrapper prompt) `k` times with `original`, `k` times with `candidate` and `k` times with the **control** - a byte-identical copy of `original` - each run a fresh context on the **identical** case input. Give the three version directories neutral names (for example `v1`, `v2`, `v3` in shuffled order) so no path tells a runner which version it holds. Save the transcripts as `<runs>/<case>/original-<i>.md`, `candidate-<i>.md` and `control-<i>.md`.
2. **Blind the transcripts.** `python3 "${CLAUDE_SKILL_DIR}/scripts/ab_aggregate.py" blind --runs <runs> --out <blind> --key <key.json> --seed <n>` copies every transcript to a shuffled neutral label (`<blind>/<case>/R1.md` ...) and writes the label-to-run key to a path outside `<blind>`.
3. **Judge blind.** One judge per case (`references/equivalence-judge-prompt.md`) reads the case input and the `3k` labelled transcripts in `<blind>/<case>/` - never the key, the runs directory or the documents. It lists every distinct behaviour any transcript shows, marks which transcripts show each one, and scores each transcript's directness. It writes `<judgements>/<case>.json`.
4. **Aggregate.** `python3 "${CLAUDE_SKILL_DIR}/scripts/ab_aggregate.py" aggregate --key <key.json> --judgements <judgements> --out <report.json>` maps the labels back and applies the decision rule below. The rule is arithmetic, so it lives in the script, not in a judge's reading.
The judge compares observed behaviour to observed behaviour, never a transcript against what a document *says* it should do. It never learns which transcript came from which version, so its own leanings - towards calling a delta a loss, or towards the familiar - fall on all three versions alike, and the control measures them. The full contract and schema are in `references/ab-equivalence.md`; the judge prompt is in `references/equivalence-judge-prompt.md`.
### The decision rule
With `k` runs per version, "most" is more than `k/2` and "few" is fewer than `k/2`. Per behaviour, the script counts the runs of each version that show it:
- A behaviour is in the original's **baseline** when most original runs show it. One that only some original runs show is noise in the original itself and is never a loss.
- **`lost`** - a baseline behaviour that most candidate runs miss and few control runs miss.
- **`gained`** - a behaviour outside the baseline that most candidate runs show and few control runs show.
- **`noisy`** - the candidate or the control departs from the original's majority, but the control does not stay on the original's side. Variation, not a change; it is reported and never counted.
- **`unchanged`** - otherwise.
With `k = 3`, a loss needs at least 2 of 3 candidate runs to miss the behaviour and at most 1 of 3 control runs to miss it. With an even `k`, an exact half is neither most nor few, so it never counts.
The rule still lets some noise through. For a behaviour that every version misses at random with probability `p`, the chance it reads `lost` is:
| `k` | `p` = 0.1 | `p` = 0.2 | `p` = 0.3 |
|-----|-----------|-----------|-----------|
| 3 | 0.026 | 0.083 | 0.133 |
| 5 | 0.008 | 0.051 | 0.114 |
| 7 | 0.003 | 0.031 | 0.096 |
A case with several such behaviours multiplies the chance. Read the counts in `behaviour_delta` before acting on a regression: a loss at "candidate 0/3, control 3/3" is a removed behaviour; one at "candidate 1/3, control 2/3" rests on two runs. Before adding text back for a narrow loss, re-run the candidate and the control at a higher `repeats`; a real loss stays, noise usually does not.
The rule can also miss a real loss. A behaviour the candidate never shows reads `noisy`, not `lost`, when the original falls short of a majority or the control misses it in most runs. For a behaviour the original and the control miss at random with probability `p`, the chance a removed behaviour goes uncounted is:
| `k` | `p` = 0.1 | `p` = 0.2 | `p` = 0.3 |
|-----|-----------|-----------|-----------|
| 3 | 0.055 | 0.197 | 0.385 |
| 5 | 0.017 | 0.112 | 0.300 |
| 7 | 0.005 | 0.066 | 0.236 |
So each case also lists `suspects`: every `noisy` behaviour that no candidate run shows although some original run does, and `summary.suspects` counts them. A pass with suspects is not clean: re-run the candidate and the control at a higher `repeats`, or keep the text behind each suspect, before accepting it.
### Baseline caching (the original and the control are captured once)
The `original` never changes across a multi-round transform loop, so its `k` transcripts per case, and the control's `k`, are **captured once and reused across every round**. Only the candidate's `k` runs are re-run each round; each round blinds and judges the full `3k` set afresh with a new seed, because the judge's behaviour list must cover the new candidate runs. Re-running the original each round wastes runner budget for no gain: the control already measures the original's own variation. The caller passes the cached transcripts back in on rounds >= 2. A budget ceiling on candidate re-runs belongs to the caller's loop, not here.
## Verdict categories
Per case, the script returns exactly one verdict:
| Verdict | Meaning | What it cites |
|---------|---------|---------------|
| `equivalent` | No behaviour is `lost` or `gained`. `noisy` behaviours and incidental wording differences are still `equivalent`. | Nothing beyond the verdict and the noise floor. |
| `candidate-regressed` | At least one behaviour is `lost`. This is the failing verdict, even alongside a gain elsewhere. | Each **lost behaviour**, with its run counts per version. |
| `candidate-diverged` | No behaviour is `lost`, at least one is `gained` - a different-but-not-worse change. | Each **gained behaviour**, with its run counts per version. Not necessarily worse; documented for the caller's judgement. |
Every verdict carries the case's **noise floor**: the control's miss rate over the baseline behaviours, the candidate's miss rate beside it, and `control_departures`, the number of behaviours where the control itself left the original's majority. A case whose control departs often is too noisy to support a fine-grained claim at that `k`; raise `repeats` or narrow the case.
## Efficiency signal (alongside every verdict)
Independent of the verdict, the judge scores each transcript's **directness** - how directly the runner acted versus how much it had to unpack or reinterpret the instruction before acting - and the script reports the low median per version:
| Field | Type | Meaning |
|-------|------|---------|
| `original_directness` | integer 1-5 | The low median of the original runs' scores: 5 = acted immediately, no reinterpretation; 1 = had to unpack, infer, or work around the instruction heavily before acting. |
| `candidate_directness` | integer 1-5 | The same measure over the candidate runs. |
| `interpretation_notes` | string | The judge's per-run notes for the original and candidate runs - the qualitative evidence behind the two scores. |
The signal is read from the runner self-report (`references/runner-prompt.md`): *steps followed / skipped*, *ambiguities hit and how resolved*, *improvisation beyond the skill*, and *any point it wanted to deviate but followed literally* all reveal how much interpretive work each version forced. Directness is scored from interpretive work shown, **not** from document length - a shorter document that forced more reinterpretation is *less* direct, not more.
Why it exists: compression's gate is **strict no-regression** (sameness alone). But the optimizer family includes transforms that claim *behaviour-preserving-but-lighter* - directive-clarity rewrites instructions the model must unpack into directives that name the action. Such a transform can only be validated if the harness **measures the lightness, not just the sameness**: its gate is no-regression **and** a measured efficiency gain (`candidate_directness` > `original_directness` with no `candidate-regressed`). Recording the signal here, on every A/B run, is what lets those transforms prove a measured gain instead of asserting one. This capability records the signal; it never gates on it - whether a gain is required is the calling transform's gate.
## Output schema
```json
{
"cases": [
{
"case_id": "string",
"verdict": "equivalent|candidate-regressed|candidate-diverged",
"behaviour_delta": "string",
"efficiency_signal": {
"original_directness": 1,
"candidate_directness": 1,
"interpretation_notes": "string"
},
"repeats": 3,
"noise_floor": {
"control_miss_rate": 0.0,
"candidate_miss_rate": 0.0,
"control_departures": 0
},
"behaviours": [
{"id": "b1", "text": "string", "original": 3, "candidate": 3, "control": 3, "status": "unchanged|lost|gained|noisy"}
],
"suspects": ["string"]
}
],
"summary": {
"pass": true,
"regressions": 0,
"divergences": 0,
"equivalents": 0,
"repeats": 3,
"control_departures": 0,
"suspects": 0
}
}
```
- `case_id` - the transfer-set case identifier.
- `verdict` - one of the three categories above.
- `behaviour_delta` - for `candidate-regressed`, each lost behaviour with its run counts; for `candidate-diverged`, each gained behaviour; empty for `equivalent`.
- `efficiency_signal` - the per-version directness and notes described above.
- `noise_floor` - the control's and the candidate's miss rates over the baseline behaviours (misses / (baseline behaviours x `k`)) and the control's departures.
- `behaviours` - every behaviour the judge listed, with the number of runs of each version that showed it and its status.
- `suspects` - each `noisy` behaviour no candidate run shows although some original run does; a possible loss hidden by noise.
- `summary.regressions` / `divergences` / `equivalents` - counts of each verdict across `cases`; `summary.control_departures` and `summary.suspects` sum the cases'.
- **`summary.pass` is `true` if and only if zero cases are `candidate-regressed`.** Divergences do not fail the run - they are surfaced for the caller's judgement. This encodes the strict no-regression gate: the candidate is accepted only when it loses nothing that outlasts the control's noise.
## Execution modes
<!-- chat-replace:execution-mode-rule -->
The capability runs the same mechanism in every mode; modes differ only in how the runs and the judge are spawned. The caller's harness selects the mode; A/B equivalence runs inside whatever mode it is handed.
**Solo mode** (chat / standalone ZIP, no subagents): a single agent works each case sequentially - it applies each version `k` times via the runner wrapper, then lists the behaviours and marks each transcript with the equivalence-judge prompt, then applies the decision rule above by hand. One agent that ran the versions cannot judge them blind and cannot give each run a fresh context, so a solo result states that it is not blind and carries a weaker claim than a sub-agent run.
<!-- chat-skip:start -->
**Phased sub-agent mode** (Agent Teams flag off): the lead spawns a fresh runner subagent per run (`3k` per case on the first round, `k` after), runs `scripts/ab_aggregate.py blind`, spawns a fresh judge subagent per case on the blind directory, then runs `scripts/ab_aggregate.py aggregate`. With no persistent agents, the cached original and control transcripts are injected into each round so only the candidate is re-run. Pick runners by cost: the runner model is the one under test, so keep it fixed across versions and rounds.
**Team mode** (Agent Teams flag on, `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`): the equivalence judge can run as a persistent background teammate (`Agent` with `run_in_background: true`, joined to the session's single implicit team), communicating with the lead via `SendMessage`; ephemeral runners are spawned per round and shut down after. A persistent judge must still be handed only the blind directory each round. As with the forge loop, shut each teammate down with a `SendMessage` shutdown_request at the end of the run; nothing persists to block a future run. Send `shutdown_request` **once**; the teammate approves with a structured `shutdown_response` (addressed to `team-lead`, echoing the `request_id`, `approve: true`), which terminates it. Treat that approval, or an already-exited teammate, as the completion signal; any that linger reap when the session exits.
No persistent team is required by the capability itself - the judge holds no across-round memory of its own; the cached original and control transcripts are the only state carried between rounds, and the caller owns them.
<!-- chat-skip:end -->
## What this capability does not do
- It does not derive or confirm the transfer set - the caller does, and signs off on coverage.
- It does not decide whether the candidate is good in absolute terms - that is an absolute-quality gate, a different run.
- It does not add back lost behaviour or regenerate candidates - on a regression it names what was lost; the caller's loop acts on that.
- It does not gate on the efficiency signal - it records it. Whether a measured efficiency gain is required is the calling transform's gate, not this capability's.
Files in this skill
- SKILL.md
- references/ab-equivalence.md
- references/equivalence-judge-prompt.md
- references/runner-prompt.md
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.