Cogitator
Evaluation Framework

Reporters

Output evaluation results to the console, JSON, CSV, JUnit XML, Markdown or HTML files, GitHub Actions annotations, or a CI verdict that sets the exit code, render comparisons, and run suites as Vitest tests.

Overview

Reporters format and output eval suite results. Call result.report() with one or more reporter types after a run completes.

const result = await suite.run();

result.report('console');
result.report('json', { path: './reports/eval.json' });
result.report(['console', 'json', 'csv'], { path: './reports/eval' });

You can also use the standalone report() function, with a suite result or any object of the same shape (results, aggregated, assertions, stats):

import { report } from '@cogitator-ai/evals';

report(result, 'console');
report(result, ['json', 'csv'], { path: './eval-report' });
ReporterOutput
consoleColored table of metrics, assertions and a summary line
jsonWrites <path>.json with every case, score and aggregate
csvWrites <path>.csv with one row per case
junitWrites <path>.xml, a JUnit report CI systems show as test results
githubPrints GitHub Actions annotations and writes the job summary
ciPrints a short verdict and sets process.exitCode to 1 on failure
markdownWrites <path>.md, a compact summary for a pull request comment
htmlWrites <path>.html, a self-contained page for light and dark

File reporters create missing directories. result.report() writes each case as { case: { input, expected }, output, duration, error?, truncated?, iterationLimitReached?, paused?, scores }, and passing the suite result to the standalone report() writes the full case results (including usage and context).

The run flags come from an agent target's run: truncated means the answer stopped at the output token limit, iterationLimitReached that tool calls used up maxIterations, and paused that the run paused for tool approvals. A case carries a flag only when it is set, and the json, csv and junit reports show it.

Console Reporter

Prints a formatted table of aggregated metrics, assertion results, and a summary line to stdout. When the aggregates say how many cases each metric was scored on (count), the table gets a Cases column: an errored case is not scored, so a metric can cover fewer cases than the run.

result.report('console');

Example output:

Metric        Mean      Median    P95       Min       Max       Cases
──────────────────────────────────────────────────────────────────────
exactMatch    0.9200    1         1         0         1         48
contains      0.9600    1         1         0         1         48

Assertions
  ✓ threshold(exactMatch) exactMatch = 0.92 >= 0.9
  ✗ threshold(contains) contains = 0.96, expected >= 0.98

Summary: 50 cases | 2 errored | 12340ms | $0.52 | 1 passed 1 failed

Assertions show green check marks for passes and red crosses for failures.

JSON Reporter

Writes the full result data to a JSON file. Includes per-case results with scores and run flags, the agent's toolCalls, toolResults, retrieved passages and turns, the traceId and versioned prompt of an agent run (see Experiment Tracking), every trial in trials when the suite ran several, aggregated metrics with their count, assertions, and stats. The console and GitHub reporters show the trials per case in their summary (2 cases x 3 trials).

result.report('json', { path: './eval-report.json' });

Default path: eval-report.json

The JSON output includes:

{
  "results": [
    {
      "case": { "input": "...", "expected": "..." },
      "output": "...",
      "duration": 1234,
      "scores": [
        { "name": "exactMatch", "score": 1 },
        { "name": "contains", "score": 1 }
      ]
    }
  ],
  "aggregated": {
    "exactMatch": { "name": "exactMatch", "mean": 0.92, "median": 1, "p95": 1, "count": 48, ... }
  },
  "assertions": [
    { "name": "threshold(exactMatch)", "passed": true, "message": "..." }
  ],
  "stats": { "total": 50, "duration": 12340, "cost": 0.52 }
}

CSV Reporter

Writes per-case results to a CSV file with one row per eval case. Metric scores are included as additional columns.

result.report('csv', { path: './eval-report.csv' });

Default path: eval-report.csv

Output format:

input,expected,output,duration,exactMatch,contains
What is 2+2?,4,4,89,1,1
Capital of France?,Paris,paris,124,0,1

Fields containing commas, quotes, or line breaks are quoted. When any case carries a run flag, the report gets a column for that flag (truncated, iterationLimitReached, paused) after duration, with true on the flagged rows:

input,expected,output,duration,truncated,exactMatch
Summarize the report,...,The report covers,2310,true,0

Markdown Reporter

Writes a compact summary of the run, made to be posted as a pull request comment.

result.report('markdown', { path: './reports/eval' });

Default path: eval-report.md

It holds a title with the suite's name, a line with the totals (cases, trials per case when there are several, errored cases, metric errors, duration, cost, assertions passed and failed), a table of each metric's mean and the cases it covers, the assertions with pass or fail, and the failures: each errored case with its error and each metric that failed on a case, for every trial with its number (trial 2: metric relevance failed: ...) when the suite ran several. At most 25 failures are listed, the rest counted.

### Eval results: support-agent

**50** cases | **1** errored | 32358 ms | 0.0412 USD | assertions: **1** passed, **1** failed

| Metric     |   Mean | Cases |
| ---------- | -----: | ----: |
| exactMatch | 0.9200 |    49 |

| Assertion             | Result   | Details                                         |
| --------------------- | -------- | ----------------------------------------------- |
| threshold(exactMatch) | pass     | exactMatch = 0.92 >= 0.9                        |
| maxErrorRate(0)       | **fail** | 1 of 50 cases errored (2%), expected at most 0% |

**Failures** (1)

| Case                      | Problem                        |
| ------------------------- | ------------------------------ |
| [7] Capital of Australia? | error: Timed out after 30000ms |

Every value from the run is escaped (<, &, |, \ and line breaks), so no answer can break a table or hide the rest of the comment.

gh pr comment "$PR" --body-file reports/eval.md

HTML Reporter

Writes the run as one self-contained page: inline CSS that follows the reader's light or dark color scheme, no scripts and no external assets, so it opens from a CI artifact or an email attachment as it is.

result.report('html', { path: './reports/eval' });

Default path: eval-report.html

The page shows the totals, the aggregated metrics (mean, p50, p95, min, max, cases), the assertions, and every case with its input, expected answer, output (long outputs and conversations folded), scores, status (answered or the error, run flags, trials answered and the failures of each trial) and, for agent targets, the trace id and prompt version. Every value is HTML-escaped.

Comparisons

reportComparison(comparison, type, options?) renders a comparison, from compareRuns() or from EvalComparison, as console, markdown (<path>.md) or html (<path>.html), with the default path eval-comparison. See Reporting a Comparison.

reportComparison(compareRuns(base, head), ['console', 'markdown'], {
  path: './reports/comparison',
});

CI Reporter

Minimal output designed for CI pipelines. Prints one line per assertion and sets process.exitCode = 1 when any assertion fails.

result.report('ci');

Example output:

Eval: 50 cases | 12340ms | $0.52
  PASS threshold(exactMatch)
  FAIL threshold(contains): contains = 0.96, expected >= 0.98
Result: 1 passed, 1 failed

The reporter does not end the process. Node exits with code 1 once the script finishes, so the CI job fails, while buffered output still flushes and the reporters, afterAll hooks and cleanup code that come after it still run. Use it in your eval script:

{
  "scripts": {
    "eval": "tsx eval/run.ts",
    "eval:ci": "tsx eval/run-ci.ts"
  }
}
// eval/run-ci.ts
const result = await suite.run();
result.report('ci');

JUnit Reporter

Writes a JUnit XML report, which GitLab, Jenkins, CircleCI, Azure Pipelines and the GitHub test report actions show as test results.

result.report('junit', { path: './reports/eval' });

Default path: eval-report.xml

The document holds one <testsuite name="eval"> inside <testsuites>:

  • each case is a <testcase> named by its index and a shortened input, with a <failure> when the case errored and a <system-out> listing its scores and run flags,
  • each assertion is a <testcase> named after the assertion, with a <failure> carrying its message when it did not pass.
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="eval" tests="4" failures="2" errors="0" time="2.620">
  <testsuite name="eval" tests="4" failures="2" errors="0" skipped="0" time="2.620">
    <testcase name="[1] What is 2+2?" classname="eval.cases" time="0.120">
      <system-out>exactMatch: 1</system-out>
    </testcase>
    <testcase name="[2] Capital of France?" classname="eval.cases" time="2.500">
      <failure message="Timed out after 2000ms" type="CaseError">Timed out after 2000ms</failure>
    </testcase>
    <testcase name="threshold(exactMatch)" classname="eval.assertions" time="0.000">
      <failure message="exactMatch = 0.5, expected &gt;= 0.9" type="AssertionFailure">exactMatch = 0.5, expected &gt;= 0.9</failure>
    </testcase>
    <testcase name="threshold(latency.p95)" classname="eval.assertions" time="0.000"/>
  </testsuite>
</testsuites>

tests and failures count cases and assertions together, and time is in seconds. Every value is XML-escaped, and characters XML 1.0 does not allow (control characters, lone surrogates) are replaced with U+FFFD, so model output can never break the report.

GitHub Reporter

For GitHub Actions. Prints workflow commands that GitHub shows as annotations on the run and the pull request:

  • ::error for each failed assertion and each errored case,
  • ::warning for each metric score that failed (score.error).
result.report(['github', 'ci']);
::error title=Eval case [2] Capital of France?::Timed out after 2000ms
::warning title=Eval metric relevance on case [1] What is 2+2?::could not parse judge response
::error title=Eval assertion threshold(exactMatch)::exactMatch = 0.5, expected >= 0.9

Messages escape % and line breaks, and titles also escape : and ,, as the workflow command format requires.

When GITHUB_STEP_SUMMARY is set, which GitHub does in every job step, the reporter also appends a Markdown summary to the job page: the totals, a table of the aggregated metrics with mean, p50, p95 and the number of cases scored, and every assertion with pass or fail.

# .github/workflows/eval.yml
- name: Run evals
  run: pnpm eval:ci
// eval/run-ci.ts
const result = await suite.run();
result.report(['github', 'junit', 'ci'], { path: './reports/eval' });

Multiple Reporters

Pass an array of reporter types to output in multiple formats at once:

result.report(['console', 'json', 'csv'], { path: './reports/eval' });

The path option is a base path shared across file-based reporters: a trailing .json, .csv, .xml, .md or .html is dropped and each reporter adds its own extension, so ./reports/eval (or ./reports/eval.json) gives ./reports/eval.json, ./reports/eval.csv, ./reports/eval.xml, ./reports/eval.md and ./reports/eval.html. The other reporters run in the order given, and ci always runs last, so its verdict is the final line of the output.

Vitest

describeEval from @cogitator-ai/evals/vitest runs a suite as a Vitest test file, so evals sit next to your other tests and show up in the Vitest UI, its reporters and its exit code. Vitest is an optional peer dependency of the package:

pnpm add -D vitest
// eval/qa.eval.test.ts
import { afterAll } from 'vitest';
import { describeEval } from '@cogitator-ai/evals/vitest';
import { suite } from './qa-suite';

const qa = describeEval('qa agent', {
  suite,
  run: { maxCases: 50 },
  timeout: 5 * 60_000,
});

afterAll(() => qa.result().report('junit', { path: './reports/qa' }));

describeEval(name, { suite, run?, timeout? }) registers a describe block:

  • beforeAll runs the suite once with run (EvalRunOptions: maxCases, signal),
  • each case from suite.cases(run?.maxCases) gets a test named by its index and shortened input, which fails with the case error when every attempt failed,
  • an assertions test fails and lists every assertion that did not pass.

timeout is how long the run may take, 10 minutes by default. When it runs out, the run is cancelled through its AbortSignal, so no attempt keeps running and paying in the background.

If the run itself fails (a cancelled signal, a timeout, an invalid maxCases), every test of the block fails with that cause instead of a confusing follow-up error.

describeEval returns { result }. result() gives the EvalSuiteResult once the run has finished, so call it in a later test or in afterAll, for example to write reports or save a baseline. It throws with the cause when the run failed, and before the run has finished.

Vitest Matchers

evalMatchers adds matchers for eval results to expect. Register them once, in the test file or a setup file. They come from @cogitator-ai/evals/matchers, which augments Vitest's Assertion and AsymmetricMatchersContaining types, so the matchers are typed wherever it is imported. Those types changed in Vitest 5, so the entry needs Vitest 5, while describeEval works from Vitest 3.

import { expect, it } from 'vitest';
import { evalMatchers } from '@cogitator-ai/evals/matchers';

expect.extend(evalMatchers);

it('books a table', async () => {
  const result = await suite.run();
  const [booking] = result.results;

  expect(booking).toHaveCalledTool('book_table', { guests: 2 });
  expect(booking).toFollowTrajectory(['find_restaurant', 'book_table'], { order: 'in-order' });
  expect(booking).toHaveRetrieved('doc:menu');
  expect(booking).toScoreAtLeast('toolCalls', 1);
  expect(result).toScoreAtLeast('trajectory', 0.8);
});
MatcherPasses when
toHaveCalledTool(name, args?)The case called name, over any turn, with arguments holding args (other arguments allowed)
toFollowTrajectory(names, { order? })'exact' (default): exactly those calls in that order. 'in-order': in that order, others between allowed. 'any-order': each of them, in any order
toHaveRetrieved(idOrText)A retrieved passage has that id or that text, or one of the two texts contains the other and the contained one has at least three words
toScoreAtLeast(metric, min)A case result's score of the metric, or a suite result's aggregated mean, is at least min

A failure names what the case did instead, such as expected the case to call cancel({"id":1}), it made search({"q":"paris"}), book({}). toScoreAtLeast throws when the case or the suite has no such metric, listing the ones it has, so a typo never passes under .not.

CI Integration Example

import {
  Dataset,
  EvalSuite,
  exactMatch,
  contains,
  latency,
  threshold,
  noRegression,
} from '@cogitator-ai/evals';

const dataset = await Dataset.fromJsonl('./eval/dataset.jsonl');

const suite = new EvalSuite({
  dataset,
  target: { fn: myAgentFn },
  metrics: [exactMatch(), contains()],
  statisticalMetrics: [latency()],
  assertions: [
    threshold('exactMatch', 0.9),
    threshold('contains', 0.95),
    threshold('latency.p95', 5000),
    noRegression('./eval/baseline.json'),
  ],
});

const result = await suite.run();
result.report(['console', 'json', 'junit', 'github', 'ci'], { path: './eval/report' });

On this page