Skip to content

eval ​

Inspect saved statelog traces, compare two responses against a goal, or compare two whole run directories. Use the CLI to run evaluation suites.

Extract and judge eval records ​

ts
import { evalExtract, evalJudge } from "std::agency/eval"

node main() {
  const record = evalExtract("runs/demo/statelog.jsonl")
  print(record.evalOutputs)

  const verdict = evalJudge(
    "Prefer the answer that names the capital exactly.",
    "runs/a/statelog.jsonl",
    "runs/b/statelog.jsonl",
  )
  print(verdict.winner)
}

Judge whole run directories ​

ts
import { evalJudgeSuite } from "std::agency/eval"

node main() {
  const verdict = evalJudgeSuite("runs/baseline", "runs/candidate")
  print(verdict.winner)
}

Types ​

EvalValue ​

ts
export type EvalValue = {
  value: any;
  threadId?: string;
  tMs: number;
  truncated?: boolean
}

(source)

EvalRecord ​

ts
export type EvalRecord = {
  traceId: string;
  recordVersion: number;
  formatVersion: number;
  durationMs: number;
  source: string;
  evalValues: EvalValue[];
  evalOutputs: EvalValue[];
  threads: Record<string, any>[];
  events: Record<string, any>[];
  interrupts: Record<string, any>[];
  errors: Record<string, any>[];
  incomplete: Record<string, any>[];
  metrics: Record<string, any>;
  warnings: string[]
}

(source)

PairwiseVerdictInput ​

ts
export type PairwiseVerdictInput = {
  path: string;
  response: string;
  truncated?: boolean
}

(source)

PairwiseVerdict ​

ts
export type PairwiseVerdict = {
  verdictVersion: number;
  goal: string;
  inputs: PairwiseVerdictInput[];
  winner: string;
  confidence: number;
  reasoning: string;
  generatedAt: string
}

(source)

JudgeAggregationPolicy ​

ts
export type JudgeAggregationPolicy = {
  samples: number;
  confidenceThreshold: number;
  marginThreshold: number;
  positionBias: string
}

(source)

VerdictSide ​

ts
export type VerdictSide = {
  path?: string;
  status: string;
  response?: string;
  truncated?: boolean;
  errorMessage?: string
}

(source)

JudgeSample ​

ts
export type JudgeSample = {
  winner: string;
  confidence: number;
  reasoning: string;
  order: string
}

(source)

InputVerdict ​

ts
export type InputVerdict = {
  inputId: string;
  goal: string;
  inputs: VerdictSide[];
  winner: string;
  confidence: number;
  reasoning: string;
  samples: JudgeSample[];
  generatedAt: string
}

(source)

SuiteVerdict ​

ts
export type SuiteVerdict = {
  verdictVersion: number;
  generatedAt: string;
  policy: JudgeAggregationPolicy;
  winsA: number;
  winsB: number;
  ties: number;
  winner: string;
  perInput: InputVerdict[]
}

(source)

Functions ​

evalExtract ​

ts
evalExtract(statelogPath: string): EvalRecord

Read a structured evaluation record from a statelog trace.

Read one trace as a normalized record for analysis. The record is computed from the statelog rather than stored as a separate file. Use evalOutputs to inspect what will be graded.

Parameters:

NameTypeDefaultDescription
statelogPathstringA statelog JSONL file containing exactly one trace.

Returns: EvalRecord

Needs: fileRead

(source)

evalJudge ​

ts
evalJudge(
  goal: string,
  recordPathA: string,
  recordPathB: string,
): PairwiseVerdict

Compare two saved agent responses against a grading goal.

Runs the bundled pairwise judge, making an LLM call for each comparison. The verdict names A, B, or tie, with confidence from zero to 100. For comparisons sensitive to response order, judge both orders and reconcile the results. Each path must name a single-trace statelog.

Parameters:

NameTypeDefaultDescription
goalstringThe criteria the judge should use to compare the responses.
recordPathAstringA statelog JSONL file containing the first run's single trace.
recordPathBstringA statelog JSONL file containing the second run's single trace.

Returns: PairwiseVerdict

Needs: fileRead, llm

(source)

evalJudgeSuite ​

ts
evalJudgeSuite(
  runA: string,
  runB: string,
  samples: number = 3,
  confidenceThreshold: number = 50,
  marginThreshold: number = 0,
  positionBias: "swap" | "none" = "swap",
): SuiteVerdict

Compare two evaluation run directories and aggregate their per-test verdicts.

Compares matching test IDs across two run directories. Goals and test IDs come from the run annotations saved with each trace. Missing or failed runs and missing goals get deterministic verdicts without an LLM call. Successful comparisons make the requested number of judge calls.

Per-test winners below the confidence threshold count as suite ties. The overall win-count difference must exceed the margin threshold to choose a suite winner.

Parameters:

NameTypeDefaultDescription
runAstringThe first run directory containing statelog traces and run annotations.
runBstringThe second run directory containing statelog traces and run annotations.
samplesnumber3The number of judge calls for each comparable test.
confidenceThresholdnumber50Treat per-test confidence below this zero-to-100 threshold as a suite tie.
marginThresholdnumber0Require the suite's win-count difference to exceed this number.
positionBias"swap" | "none""swap"Use swap to alternate response order across samples, or none to keep A first.

Returns: SuiteVerdict

Needs: fileRead, llm

(source)