Dry runs, evals and replay

Try an agent on a fork without merging or sending anything, score it with eval suites (JUnit output), and replay a past run against new code.

An agent function's job works in a world and proposes its changes when it ends well. A trial runs the same code the same way, against the same data, and stops short of the merge: you see what it would have changed, what it would have sent and what its merge policy would have decided, and nothing reaches the data or leaves the server.

There are three kinds, the run's mode:

ModeStarted byFor
dryforkbase try, the dashboard's Try tab, invoke with "mode": "dry"trying a function by hand before you let it loose
evalforkbase evaltest cases with expectations, in CI
replayforkbase replay, POST /jobs/v1/replayrunning a past job again, with new code, and comparing

A live run's mode is live. Runs and jobs show their mode.

What a trial can't do

  • Merge. Its engine agent has the rights read, fork and write_own only: no merge_own, no write_main. This holds whatever the code holding its token does (its DATABASE_URL, MERGE WORLD in SQL, the HTTP API). Proposing it never merges either: Forkbase ends it instead (below). A run's own token can't propose a trial at all (409 not_live): it ends when its job ends.
  • Send. Effects it queues with NOTIFY ON MERGE stay in its world, which is discarded; they are listed in its snapshot as what it would send.
  • Start anything. A trial records no events: no webhook hears of it, and no trigger starts a job from it. Its job's job.succeeded and job.failed aren't recorded either.
  • Crowd out live work. Trial jobs run in a pool of their own (jobs.trial_workers, default 2), apart from jobs.workers, and don't count toward a function's concurrency. A trial job is tried once.

Calls the code makes to other services (an LLM, an HTTP API) are made: a trial holds back only what goes through Forkbase. Use FORKBASE_RUN_MODE (below) to skip a call that does something outside.

How a trial ends

When its job ends well, the run is proposed as any agent function's is, and Forkbase, seeing a trial:

  1. takes its snapshot: the rows its world changed, with their before and after (up to agents.snapshot_rows, the rest counted), and the effects it queued;
  2. asks the engine what the run's policy would decide, with the run's own token (a merge dry run, which merges nothing, queues no review and counts toward no hourly limit): would is merge, hold, refuse, conflict or error, with the reasons;
  3. runs its checks, SQL queries in its world, keeping their rows;
  4. discards its world (and its setup world), and marks the run discarded, decided by trial.

The process gets FORKBASE_RUN_MODE (live, dry, eval or replay) beside FORKBASE_RUN_ID.

Setup

A trial may start from data you give it. setup.sql (one statement, or a list) and setup.rows ([{table, id, record}], record: null deletes the row) are written first in a setup world, forked from the data, and the run's world is forked from that. So the snapshot holds the function's changes alone, not the setup's.

Snapshots

Every live run's snapshot is kept too, taken as it is proposed (agents.snapshots, on by default), so you can see what a merged run changed after its world is gone (GET /runs/{id}/changes falls back to it) and replay it.

shell
curl -s "$URL/agents/v1/runs/run_.../snapshot" -H "Authorization: Bearer $SERVICE_KEY"
JSON
{
  "run": "run_...", "mode": "dry", "status": "discarded",
  "changes": [{ "key": "public.claims/7", "before": { "status": "new" }, "after": { "status": "approved" }, "columns": ["status"] }],
  "total": 1, "truncated": false,
  "effects": [{ "id": "...", "channel": "email.send", "payload": "{\"claim\": 7}" }],
  "would": { "decision": "merge", "reasons": null },
  "checks": [{ "name": "approved", "ok": true, "columns": ["n"], "rows": [{ "n": 1 }] }]
}

Snapshots are deleted after agents.snapshot_days (30; 0 keeps them). Columns named in agents.snapshot_mask (["users.email", "public.cards.number"]) are kept as •••, never their values.

Try

shell
forkbase try triage --payload '{"claim": 7}'
forkbase try triage --payload '{"claim": 900}' --setup-sql "insert into claims (id, amount, status) values (900, 40, 'new')"

It prints the rows changed, the effects it would send and the policy's verdict, and exits non-zero if the job failed. --version <n> runs an earlier version of the code. Over HTTP:

shell
curl -s -X POST "$URL/jobs/v1/functions/triage/invoke?wait=60" -H "Authorization: Bearer $SERVICE_KEY" \
  -H 'content-type: application/json' \
  -d '{"mode": "dry", "payload": {"claim": 7}, "setup": {"sql": "..."}, "checks": [{"name": "n", "sql": "select count(*) as n from claims"}]}'

A trial is started now and once: delay_s, run_at and idempotency_key are refused. Only a function with an agent can be tried. POST /agents/v1/runs takes the same mode, setup and checks for a run you drive yourself; propose then ends it as above and answers with the verdict, the checks and the changes.

Evals

An eval suite is a TOML file, by convention in evals/. Each case is one trial (mode = "eval") of the suite's function, and its expectations are checked against the job and the snapshot.

TOML
function = "triage"
ignore_columns = ["updated_at"]     # left out when a case's repeats are compared
decision_columns = ["status"]       # optional: repeats must agree on these columns only
max_cost_usd = 0.50                 # optional: no more cases start once its model calls cost this

[[case]]
name = "approves a small claim"
payload = { claim = 1 }
repeat = 3
setup.sql = ["insert into claims (id, amount, status) values (1, 40, 'new')"]

  [[case.expect]]
  status = "succeeded"              # how the job ended

  [[case.expect]]
  changes = "claims"                # rows of this table it changed
  count = 1                         # exactly (default: at least one)
  match = { status = "approved" }   # on the new values

  [[case.expect]]
  no_changes = "payments"

  [[case.expect]]
  action = "email.send"             # an effect it queued, by channel
  match = { template = "approved" } # on its JSON payload

  [[case.expect]]
  would = "merge"                   # its policy's verdict

  [[case.expect]]
  sql = "select status from claims where id = 1"   # run in its world before it is discarded
  rows = [{ status = "approved" }]                  # or count = n

  [[case.expect]]
  guardrail = "pii"                 # its policy's guardrails found this: a kind or what ("email", a tool)
                                    # no_guardrail = true: found nothing (or "injection": nothing of that kind)

  [[case.expect]]
  max_cost_usd = 0.05               # what its model calls cost, at most
  max_tokens = 20000                # tokens they used, at most

Values match loosely (1 matches "1"), and a match or rows entry names only the columns it cares about.

repeat (1 to 20) runs a case again: every run must pass, and every run must agree with the first on the rows it changed, the effects it queued and the verdict, leaving out ignore_columns (and, with decision_columns, every other column). Agents built on a model don't always do the same thing twice; repeat finds out how often they don't.

shell
forkbase eval                          # every evals/*.toml
forkbase eval evals/triage.toml --junit eval-results.xml
text
pass  triage / approves a small claim  (3/3 runs, 4.1s)
FAIL  triage / holds a big claim  (0/1 runs, 1.3s)
        would: hold expected, its policy would merge ()

2 case(s), 1 passed, 1 failed

It exits 1 when a case fails. --junit writes JUnit XML, which CI systems show as test results; --timeout (300) bounds one run of a case.

On the server

A suite can also be kept on the server and run there, so the team sees every run in the dashboard (Agents, Evals) and compares one version of an agent with another.

shell
forkbase eval --push evals/                   # saves each suite (named by its file) on the server

Or paste it into New suite. A suite is checked when it is saved. From its page, an operator or admin runs it against the deployed code or a version (Run suite); its cases run one at a time on the server, the same way forkbase eval runs them, and the page shows each case as it ends: what failed, the trials it made (open in Runs), what its model calls cost. Stop ends a run after the case in progress; once the suite's max_cost_usd is spent, the rest are skipped. A run whose server stopped is shown interrupted.

Compare puts two runs side by side, case by case: which cases now fail or now pass, whether the first trial of each changed the same rows, queued the same effects and got the same verdict (leaving out the suite's ignore_columns), and the change in cost and time. Run the suite before and after a change of prompt, model or code, then compare.

Route (service key; members by role)
GET /evals/v1/suitesevery suite with its last 12 runs
GET /evals/v1/suites/{name}one suite: its file, its cases, its runs
PUT /evals/v1/suites/{name}{"body": "<toml>"} saves it (admins)
DELETE /evals/v1/suites/{name}the suite and its runs (admins)
POST /evals/v1/suites/{name}/runs{"version"?: n} starts a run, answered at once (202, status running); operators and admins
GET /evals/v1/runs?suite=&limit=runs, newest first
GET /evals/v1/runs/{id}a run and each case's result: status (pending, running, passed, failed, skipped), failures, runs (its trials), cost_usd, seconds
POST /evals/v1/runs/{id}/stopno more cases start; operators and admins
GET /evals/v1/compare?a=&b=&ignore=two runs case by case: summary (fixed, broken, changed_outcomes), and per case a, b, same_status, same_outcome, outcome (as /agents/v1/compare), cost_delta_usd, seconds_delta

A run's status: running, passed, failed, stopped (stopped, or its budget spent: see error), error, or interrupted.

Replay

A replay runs a past job again as a trial: the rows its run changed are put back, in the setup world, as they were before it (from its snapshot), and the job runs with the same payload, by default at the function's deployed version.

shell
forkbase replay run_01J... --version 4 --ignore updated_at

It prints the replay's changes and then how they differ from the original run's: rows changed differently, rows only one of them changed, the effects, the verdict. It exits 0 when they are the same. Over HTTP, POST /jobs/v1/replay {run, version?, function?, checks?} starts it, and GET /agents/v1/compare?a=<run>&b=<run>&ignore= compares any two runs' snapshots.

What a replay can't put back: rows the run read but didn't change are as they are now, not as they were (the engine doesn't fork at a past time), and columns masked by snapshot_mask are put back masked. A run whose snapshot was cut at snapshot_rows, or whose snapshot was deleted, can't be replayed.

Something wrong or missing? Edit this page on GitHub or open an issue.

Dry runs, evals and replay · Forkbase