@flow-state-dev/testing/benchmark
Interfaces
BenchmarkAdapter
A pattern's benchmark adapter: names the pattern and builds a subject from shared options so the engine can compare patterns without knowing their internals.
Properties
build
build: (opts) => BenchmarkSubject;
Materialize the pattern into a runnable subject.
Parameters
opts
Returns
patternName
patternName: string;
Registry key / display name for the pattern.
BenchmarkAdapterOptions
Options a pattern adapter consumes when materializing a benchmark subject.
Properties
model
model: string;
Executor model every generator in the materialized pattern uses.
uses?
uses?: UsesSlot;
Capabilities forwarded into the pattern's internal generators.
BenchmarkDefinition
Declarative benchmark definition for CLI/registry discovery.
Properties
baseline?
baseline?: boolean;
Append a baseline subject (default true at run time).
baselineModels?
baselineModels?: string[];
Pure-model baselines to compare against (default: one on model). List
several to ask "do the patterns beat each of these pure models?".
disableSearch?
disableSearch?: boolean;
Strip provider-native web search from every subject and the judge. Default
false. Set true when the suite's tasks are answerable from model knowledge,
so search doesn't confound the comparison with cost/latency/variance. The
fsdev benchmark --search flag overrides this back on.
judgeModel?
judgeModel?: string;
Distinct judge model id.
model
model: string;
Executor model id.
name
name: string;
Benchmark name.
patterns?
patterns?: string[];
Pattern names resolved against registry (or a registry the runner supplies).
registry?
registry?: BenchmarkRegistry;
Registry used to resolve patterns into subjects. Carried on the definition
so a runner (e.g. the fsdev benchmark CLI) stays generic — it resolves
names without importing any specific pattern package.
runs?
runs?: number;
Repetitions per (subject, task).
scorers?
scorers?: Scorer<unknown>[];
Extra deterministic code scorers.
subjects?
subjects?: BenchmarkSubject[];
Explicit subjects, when not resolving via a registry.
tasks
tasks: BenchmarkTask[];
Tasks to run. Must be non-empty.
BenchmarkRanking
A subject's standing within a category ranking.
Properties
credible
credible: boolean;
Whether the delta clears ~2× the standard error of the difference of means (and both groups have at least 2 runs). False when it could be run-to-run noise.
deltaVsBaseline
deltaVsBaseline: number;
Mean minus the baseline subject's mean (0 when no baseline).
mean
mean: number;
Mean judge score (0-1).
subject
subject: string;
Subject name.
BenchmarkReport
The aggregated, publishable benchmark report.
Properties
baselineSubjects
baselineSubjects: string[];
Every baseline subject (kind "baseline"), in first-seen order. A run may carry several — one per pure model in a cross-model comparison.
budgetExceeded
budgetExceeded: boolean;
True when maxCostUsd was exceeded and the sweep stopped early.
categories
categories: BenchmarkCategory[];
Categories present across the tasks.
judgeModel?
judgeModel?: string;
Judge model id, when distinct/known.
model
model: string;
Executor model id used.
primaryBaseline?
primaryBaseline?: string;
The baseline used as the delta reference (the same-model baseline). Other baselines are compared by absolute mean.
rankings
rankings: Record<string, BenchmarkRanking[]>;
category (or "overall") -> subjects ranked by mean desc.
runs
runs: number;
Repetitions per (subject, task).
stats
stats: SubjectCategoryStat[];
Per (subject × category) and (subject × "overall") aggregates.
subjects
subjects: string[];
Subject names included.
timing
timing: object;
Run timing.
totalMs
totalMs: number;
totalCostUsd
totalCostUsd: number;
Total estimated USD spend across all cells.
warnings
warnings: string[];
Non-fatal warnings (e.g. judge == executor self-preference).
BenchmarkRunResult
Per-cell record the engine collects before aggregation.
Properties
category
category: BenchmarkCategory;
Task category.
codeScores?
codeScores?: Record<string, number>;
Optional deterministic code scorer scores for this cell.
costUsd
costUsd: number;
Estimated USD cost for this cell (best-effort; 0 when unknown).
errored
errored: boolean;
True when the subject's sequencer errored/threw.
kind
kind: "pattern" | "baseline";
Subject kind (pattern vs baseline).
latencyMs
latencyMs: number;
Wall-clock latency (ms) for the subject run.
passed
passed: boolean;
Whether the judge score met its threshold.
run
run: number;
Repetition index (0-based).
score
score: number;
Judge score 0-1 (0 on failure).
subject
subject: string;
Subject name.
taskId
taskId: string;
Task id.
BenchmarkSubject
A runnable benchmark subject: a sequencer plus the adapter from the generic
task to the sequencer's input. baseline subjects are the simple reference
(e.g. a single-generator answer) deltas are measured against.
Properties
kind
kind: "pattern" | "baseline";
Whether this is a pattern under test or the reference baseline.
mapTask
mapTask: (task) => unknown;
Map the generic task onto this subject's input schema.
Parameters
task
Returns
unknown
model?
model?: string;
Model this subject's generators run on. The engine forces them to this model, falling back to the run's model when unset. Lets one benchmark mix subjects on different models — e.g. cheap-model patterns against a pure expensive-model baseline ("does a Haiku swarm beat raw Sonnet?").
name
name: string;
Display name, unique within a benchmark run.
sequencer
sequencer: SequencerDefinition<any, any>;
The composed sequencer the engine executes per task.
BenchmarkTask
A single benchmark task. The same prompt is fed to every subject (each
subject maps it onto its own input shape), and every subject's output is
graded by the LLM judge against the locked rubric.
Properties
category
category: BenchmarkCategory;
Task family for bucketing/ranking.
expected?
expected?: unknown;
Optional reference answer/expected value passed to code scorers.
id
id: string;
Stable identifier, surfaced in per-cell results and the report.
metadata?
metadata?: Record<string, unknown>;
Free-form task metadata (source, difficulty, etc.).
prompt
prompt: string;
Prompt fed to every subject (mapped onto each pattern's input).
rubric
rubric: string[];
Locked, published rubric — atomic criteria the LLM judge scores against.
BuildBenchmarkReportMeta
Metadata the engine supplies alongside the raw per-cell results.
Properties
budgetExceeded
budgetExceeded: boolean;
Whether the cost budget tripped.
judgeModel?
judgeModel?: string;
Judge model id, when distinct/known.
model
model: string;
Executor model id.
primaryBaseline?
primaryBaseline?: string;
Baseline used as the delta reference (the same-model baseline). Falls back to the first baseline when unset.
runs
runs: number;
Repetitions per (subject, task).
startedAt
startedAt: number;
Date.now() at sweep start, for total timing.
warnings
warnings: string[];
Accumulated warnings.
RunBenchmarkConfig
Configuration for a single runBenchmark invocation.
Properties
concurrency?
concurrency?: number;
Concurrent (subject,task,run) cells. Default 3.
disableSearch?
disableSearch?: boolean;
Strip provider-native web search (search: true) from every subject and the
judge. Default false. Set when the task suite is answerable from model
knowledge, so live search doesn't add uncontrolled cost, latency, and
variance to the comparison. Ignored when a modelResolver is injected.
Like the engine's model-forcing, this acts at the resolver: it only strips
search from models the engine resolves by id. A generator pinned to a
concrete GeneratorModel instance bypasses ctx.resolveModel, so its search
tool survives — but such a subject also escapes the fixed-model comparison
the benchmark exists to hold, so it is out of contract regardless. Subjects
must reference their model by id (BenchmarkSubject.model).
judgeModel?
judgeModel?: string;
Distinct judge model id. Defaults to model with a self-preference warning.
judgeResolver?
judgeResolver?: ModelResolver;
Judge resolver override (tests inject a mock). Built from judgeModel when absent.
maxCostUsd?
maxCostUsd?: number;
Abort + partial report when accumulated cost exceeds this.
model
model: string;
Executor model id (cheap-paid default applied by callers).
modelResolver?
modelResolver?: ModelResolver;
Executor resolver override (tests inject a mock). Built from model when absent.
runs?
runs?: number;
k repetitions per (subject, task). Default 3.
scorers?
scorers?: Scorer<unknown>[];
Extra deterministic code scorers applied uniformly (in addition to the rubric judge).
signal?
signal?: AbortSignal;
Cancels in-flight scheduling; produces a partial report.
subjects
subjects: BenchmarkSubject[];
Subjects (patterns + optional baseline) to compare.
tasks
tasks: BenchmarkTask[];
Tasks every subject is run against.
SubjectCategoryStat
Aggregated stats for one subject within one category (or "overall").
Properties
category
category: BenchmarkCategory | "overall";
Category bucket, or "overall" across all categories.
codeScores
codeScores: Record<string, number>;
Mean of each optional code scorer (from RunBenchmarkConfig.scorers) across
successful cells. Empty when no code scorers were configured.
costPerTaskUsd
costPerTaskUsd: number;
Per-cell cost (costUsd / runs) computed from the unrounded sum, so cheap
sub-cent costs that would round to 0 in costUsd keep their signal
for the $/task and score/$ ranking columns.
costUsd
costUsd: number;
Summed estimated USD cost across cells.
mean
mean: number;
Mean judge score (0-1) across successful cells.
meanLatencyMs
meanLatencyMs: number;
Mean wall-clock latency (ms) per cell.
passRate
passRate: number;
Fraction of cells that passed the judge threshold.
runs
runs: number;
Total cells scheduled for this (subject, category).
stddev
stddev: number;
Population standard deviation of judge scores.
subject
subject: string;
Subject name.
successfulRuns
successfulRuns: number;
Cells that completed without error.
Type Aliases
BenchmarkCategory
type BenchmarkCategory =
| "reasoning"
| "multi-step-research"
| "critique-revision"
| "planning"
| string & object;
Coarse task family used to bucket and rank subjects in the scorecard. The
built-in suite uses the four labels below, but a custom suite may use any
string (the (string & {}) keeps autocomplete for the built-ins while
accepting arbitrary categories).
BenchmarkRegistry
type BenchmarkRegistry = Record<string, BenchmarkAdapter>;
Lookup of pattern name → adapter, resolved by comparePatterns.
ComparePatternsConfig
type ComparePatternsConfig = Omit<RunBenchmarkConfig, "subjects"> & object;
Config for comparePatterns — runBenchmark config minus the resolved subjects.
Type Declaration
baseline?
baseline?: boolean;
Append the single-generator baseline. Default true.
baselineModels?
baselineModels?: string[];
Pure-model baselines to compare the patterns against. Defaults to one
baseline on the run's model (named single-generator). Provide several —
e.g. [model, "anthropic/claude-sonnet-5-5"] — to ask "do the patterns on
the cheap model beat both pure models?". Each is a single-generator subject
on that model, named pure-<model>.
uses?
uses?: UsesSlot;
Capabilities forwarded to each adapter's build({ uses }), so benchmarks
that need tools (web search, code execution) can run via this convenience
path rather than building subjects by hand.
Functions
baselineSubject()
function baselineSubject(opts): BenchmarkSubject;
Builds the single-generator baseline subject: one generator that answers the task prompt directly, with no coordination. Deltas in the scorecard are measured against this control — "patterns beat the naive single call" is the load-bearing claim, so every comparison includes it.
Parameters
opts
model
string
name?
string
Returns
buildBenchmarkReport()
function buildBenchmarkReport(runs, meta): BenchmarkReport;
Folds per-cell results into the aggregated, publishable report: per (subject × category) and (subject × "overall") stats, per-category rankings with baseline deltas, and credibility flags.
Parameters
runs
meta
Returns
comparePatterns()
function comparePatterns(
registry,
names,
config
): Promise<BenchmarkReport>;
Resolves names against registry (patterns run on config.model), appends
a pure-model baseline per baselineModels entry (default: one on the run
model), and runs the benchmark. Throws a clear error naming the available
patterns when a name is missing.
Parameters
registry
names
string[]
config
Returns
Promise<BenchmarkReport>
defineBenchmark()
function defineBenchmark(def): BenchmarkDefinition;
Validates and returns a benchmark definition (CLI/registry discovery shape). Identity at runtime; the validation catches an empty task suite early.
Parameters
def
Returns
estimateCostUsd()
function estimateCostUsd(modelId, usage): number;
Estimates the USD cost of one generation from its token usage. Returns 0 for unpriced models or when usage is absent — never throws.
Parameters
modelId
string
usage
GeneratorModelUsage | undefined
Returns
number
renderScorecard()
function renderScorecard(report, format): string;
Renders a report in the requested format. markdown is a publishable table
(rows = subjects, columns = categories + overall, cells = mean±stddev,
baseline marked). json pretty-prints the report. table is plain aligned
text.
Parameters
report
format
"table" | "markdown" | "json"
Returns
string
runBenchmark()
function runBenchmark(config): Promise<BenchmarkReport>;
Runs the benchmark matrix and returns a comparative report. The independent
variable is the subject (coordination shape); model, tasks, and judge are held
fixed. Subject failures are recorded as errored cells (score 0) and never
abort the sweep; exceeding maxCostUsd stops scheduling further cells and
marks the report budgetExceeded.
Parameters
config
Returns
Promise<BenchmarkReport>