---
title: Run experiments with the option lab
description: Run a matrix of variants (prompt, tools, model, thinking, sampling, tool choice) over inputs from Studio's playground, or over the runs of one failure class, judge each cell with a pass predicate, save it as an experiment you can re-run and compare, and cap its spend with runtime.Limits.
url: https://weftgo.dev/docs/observe/playground/experiments/
type: how-to
sources:
  - weft/studio/experiments.go:56-65 (pass_predicate, stored verbatim, maxPassPredicateBytes 4096), 107-112 (Unsaved), 160-175 (from_step and inputs[i].from_step must be a step ordinal; pass_predicate is N bytes, at most 4096), 290-350 (a synthetic document for an id runs carry but no definition saved)
  - weft/obsdb/db.go:405-410 (ExperimentInput.FromStep)
  - 'weft/studio/web/src/lib/predicate.ts:1-80 (the language, DEFAULT_PREDICATE, VERDICT_WORDS), 210 (NOT_JUDGED), 306-372 (COST_WORDS, passRate: n/m judged, UNJUDGED_WORDS, summarize: the cheapest column passing every row and the cheapest overall)'
  - weft/studio/web/src/lib/regex-run.ts (the answer's first 8 KiB, the refused shapes, 250 ms per answer in a worker, the 10 s load bound)
  - weft/studio/web/src/lib/matrix.ts:1-70 (MATRIX_SOURCES_MAX 20, MATRIX_WORDS, failingStep, sourcesParam), 277-320 (the estimate line, ≈ and ≥)
  - 'weft/studio/web/src/components/studio/source-matrix.tsx (the multi-source form: rows, model columns, the predicate, the estimate, Run matrix on scripted / live, the save and the issue through cellBody)'
  - weft/studio/web/src/components/studio/error-class-facet.tsx (Experiment on these N →)
  - 'weft/studio/web/src/routes/experiments.index.tsx (the matrices and replays tabs: replays when no matrix is saved; Replays: N runs under M sources; the matrices table''s columns)'
  - weft/studio/web/src/lib/experiments.ts:125-140 (EXPERIMENT_CELLS, passLine), 190-300 (answerLine, ANSWER_CHARS 80, usageWords, idTail, REPLAY_WORDS, VS_CHIP_CELLS 24, vsSourceWords, replayChanges)
  - 'W11-auditB1-fix, v0.20.2: studio/web/src/routes/experiments.$id.tsx:123-138 (?pick= validated), 497-511 (togglePick: the last two kept, replace); studio/web/src/lib/links.ts:827-870 (experimentLink, pickOf)'
  - weft/studio/web/src/routes/experiments.$id.tsx:122-153 (?issued=, ISSUED_WORDS, ISSUED_WAIT two minutes), 197 (COST_WAITS 3), 600-640 (its runs in the runs list, clone into the form, re-run all, compare the two cells)
  - 'weft/studio/web/src/lib/engine.ts (runLabel: Run A on scripted · 0 tokens; the engine per command)'
  - 'weft/CHANGELOG.md:117, 128-130, 138, 146-147 (0.19.0: pass_predicate stored; the error-class facet and the multi-source matrix; the input''s own from_step; the predicate language; the engine per command on the playground and cell re-runs; the replays tab and the unsaved synthetic document; the grid cell), 136 (the per-variant Break on moved to /runtimes)'
  - weft/studio/web/src/lib/experiment-body.ts:153-163 (an empty enabled set throws at least one tool must stay on — …; the wire cannot say no tools); weft/studio/web/src/components/studio/experiment-form.tsx:178-183 (the checkbox always toggles); weft/studio/web/src/routes/playground.tsx:1307-1310 (the throw caught into setError, nothing issued); weft/studio/web/src/panel/playground.ts:277-277 (draftProblem holds the drawer's Run)
  - 'weft/studio/playground.go:916-926 (leavesOn: only_tools when set, else tools_enabled, else every tool); weft/studio/preview.go:692-702 (onlyTools: the same rule for the preview)'
  - weft/runtime/executor.go:1376-1382 (core.OnlyTools only for a non-empty list)
  - 'weft/studio/experiments.go:17-38 (an experiment is a saved group; the join is by id alone; panel tokens refused on all three routes), 40-99 (experimentBody, experimentSummary: run_count, succeeded, last_run, cost; experimentRow; experimentView), 114-135 (checkExperiment: id rule, at least one variant and one input)'
  - weft/obsdb (ExperimentVariant, ExperimentInput, ExperimentCommand godoc)
  - 'weft/studio/playground.go:700-769 (checkRegistered: unknown tools 400, only_tools outside tools_enabled 403, the option-lab skew, an unknown model, max_steps and parallelism lower only 403, allow), 806-839 (checkNeutral: thinking, options, temperature 0..2), 852-959 (toolOverrides, parkedChoice, paramsOverride: top_p, max_tokens, stop)'
  - weft/studio/runtime/runtime.go:402-432 (Overrides, Params, ToolChoice)
  - 'weft/runtime/options.go:121-136 (Budget, Limits: counted per experiment_id; a breach rejects the next command)'
  - weft/runtime/doc.go:21-30 (commands only narrow), 104-109 (budgets never touch the app's runs)
  - weft/runtime/link.go:579-587 (budget_exceeded rejects before the ack)
  - 'weft/runtime/link.go:106, 137 (tally: map[string]*budgetState, per experiment_id, made in newLink); weft/runtime/options.go:336 (one link per Install); weft/runtime/executor.go:573-581 (tallyLocked)'
  - 'weft/runtime/executor.go:1374-1382 (only_tools, else tools_enabled, become core.OnlyTools); weft/core/agent.go:1013-1028 (narrowTools: by name); weft/core/manifest.go:180-191 (the manifest lists submit_output); weft/studio/playground.go:703-713 (names checked against the manifest); scratch proof: OnlyTools without submit_output gave ErrNoOutput'
  - 'weft/runtime/executor.go:588-613 (reserve and unreserve: a command without experiment_id counts against no cap)'
  - weft/studio/README.md:1695-1728 (the overrides and their rules; ModelResolver; defaults; version skew), 1826-1874 (the experiments pages; the id rule; drafts; copy share link; the matrix's one step; the toast), 1876-1910 (the option lab)
  - 'weft/studio/web/src/routes/playground.tsx:493-504 (variantKeyProblem: required, no leading or trailing spaces, 32 characters, no control characters, unique)'
  - 'weft/studio/experiments.go:120-170 (checkExperiment: no variant-name check)'
  - weft/studio/web/src/routes/experiments.index.tsx:343 (the filter narrows the loaded rows), 358-383 (load more, the list stops at the newest 200)
  - weft/studio/web/src/lib/api.ts:3035-3036 (EXPERIMENTS_PAGE 50, EXPERIMENTS_MAX 200)
  - 'weft/studio/web/src/routes/experiments.$id.tsx:197 (COST_WAITS 3), 397-425 (an unlisted run: re-read, then cost not read yet)'
  - 'weft/AGENTS.md:499-503 (budgets; the overrides, narrowing or neutral, each refusal naming its rule), 540-544 (/api/experiments: 50 by default, ?limit= up to 200, total; the saved command; created, run_count, succeeded, last_run, cost; experiment_id filters; any experiment_id accepted), 546-550 (the option lab on both surfaces)'
  - weft/studio/web/src/routes/experiments.index.tsx:75 (the /experiments page), weft/studio/web/src/routes/experiments.$id.tsx:117 (the /experiments/{id} page)
  - weft/studio/web/src/components/studio/experiment-form.tsx (the form's labels)
  - 'weft/CHANGELOG.md:301 (a bare /playground asks; send again; the edit textareas), 317 (the experiments list: passed, engine, source, last run; matrixSize; scripted · 0 tokens), 808 (experiment_id on /api/runs and /api/search; the whole command saved; created, run_count, cost; the id rule; the playground mints the id), 823 (drafts, copy share link, variants renamed, duplicated, removed; one from_step; the /experiments pages), 1197 (GET /api/experiments: 50 by default, ?limit= up to 200, total), 1205 (newest N of total; 50 more at a time), 1208 (Experiments not offered under a panel token), 1372 (the option lab, Go half: params, tool_choice, park_on, only_tools; the refusals; ModelResolver; defaults), 1403 (the option lab, web half), 1711 (sampling laid over the agent''s own params), 3320 (nanosecond Created/Updated), 3537 (budgets count failed runs and every chain leg; reserve and release), 3539 (the runtime rejects unknown engines, modes, thinking levels, options, out-of-range values, bad ids, from_step out of range), 4170 (the panel drawer omits an unchanged instructions override), 4509 (the matrix saved via POST /api/experiments, every cell under the experiment''s id)'
  - docs-site/examples/playground/main_test.go:TestOverrideRefusalsNameTheirRule (each refusal verbatim), TestBudgetRefusesTheNextCommand (budget_exceeded)
  - 'observed: POST and GET /api/experiments, GET /api/runs?experiment_id=, and the /playground, /experiments and /experiments/{id} pages against the example program at v0.17.0'
  - 'weft/runtime/registry.go:364-370 and weft/runtime/executor.go:588-600 (the run cap reserved at admission: exact)'
  - weft/studio/playground.go:743-749 (a registered cap of 0 is no bound), 818-825 (a 0 override is refused)
  - weft/studio/web/src/routes/playground.tsx:1314 (the page posts the definition)
  - docs-site/factcheck/playground.md (findings 5, 24-28)
---

# Run experiments with the option lab

An [experiment](https://weftgo.dev/docs/reference/glossary/#experiment) is a matrix of playground runs: each variant is one set of overrides (prompt, tools, model, thinking, sampling, tool choice), each input one source run or text, and each cell one command sent under the experiment's id. Build it on Studio's `/playground` page and press **Run matrix**, or start one from the runs list over the runs of one failure class: the page saves the definition with `POST /api/experiments`, and every cell's run carries `weft.experiment.id`, so the experiment reads back with its runs and their cost. A pass predicate such as `status = succeeded AND cost < 0.01` judges each cell, and the grid names the cheapest variant that passes every row. [`runtime.Limits`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Limits) caps what one experiment may spend in your process.

The saved definition is plain JSON. Two variants over one source run, continued from step 1:

```sh
curl -s -X POST http://127.0.0.1:8080/studio/api/experiments -d '{
  "id": "tracking-link", "name": "tracking link", "agent": "acme-support",
  "variants": [
    {"key": "a", "overrides": {}},
    {"key": "b", "overrides": {"instructions": "You are Acme'"'"'s support agent. Always include the tracking link.",
                               "options": {"temperature": 0.2}}}
  ],
  "inputs": [{"key": "src", "source_run_id": "dd66354adfaac2b44848f0c1ed75516f"}],
  "engine": "live", "side_effects": "substitute", "thread": "ephemeral",
  "from_step": 1, "source_run_id": "dd66354adfaac2b44848f0c1ed75516f"
}'
```

```json
{"id":"tracking-link","name":"tracking link","agent":"acme-support","variants":[{"key":"a","overrides":{}},{"key":"b","overrides":{"instructions":"You are Acme's support agent. Always include the tracking link.","options":{"temperature":0.2}}}],"inputs":[{"key":"src","source_run_id":"dd66354adfaac2b44848f0c1ed75516f"}],"engine":"live","side_effects":"substitute","thread":"ephemeral","from_step":1,"source_run_id":"dd66354adfaac2b44848f0c1ed75516f","created":"2026-10-18T10:13:09.477022685Z","updated":"2026-10-18T10:13:09.477022685Z","run_count":2,"succeeded":2,"last_run":"2026-10-18T10:13:07.374947632Z","cost_usd":0,"cost_known":true,"cost_badge":"scripted","cost_reason":"a scripted model: nothing bills it, an exact $0","cache":"exact","runs":null}
```

The two cells had already run with `"experiment_id": "tracking-link"`, so the save finds them: `run_count` 2, `succeeded` 2.

## Experiments

On the `/playground` page, each variant is a column: **+ variant** adds one, and a variant can be renamed, duplicated and removed. A variant's name is required, at most 32 characters, with no leading or trailing spaces and no control characters, and unique in the form ("variant B already exists"). The name keys the cells and the experiment's variants. The **Experiment matrix** below the form adds inputs with **+ input**. Its header names the shape and the step: "Experiment matrix · 1 variant × 1 input · over the source run · from step 1". Every cell continues from that one `from_step`, the source block's step picker; past step 0 an input row's text is not sent, and the cell runs with the page's transcript edits instead.

Each variant runs on the engine the command can take, chosen as the replay drawer chooses it ([Choose the engine](https://weftgo.dev/docs/observe/playground/replay/#choose-the-engine)): two radios per variant, and Run names the variant and the engine, **Run A on scripted · 0 tokens** or **Run A live on `<model>` · ≈ $x**. An engine you pick rides the URL and the form. Breakpoints are not set per variant: the form points to [Runtimes](https://weftgo.dev/docs/observe/playground/runtimes/#breakpoints), with the count in force. The playground's Run and Run matrix wait for the preview and hold on its refusal and on the [target check](https://weftgo.dev/docs/observe/playground/replay/#the-target-check).

**Run matrix** has the page save the definition (`POST /api/experiments`) and issue every cell's command under the experiment's id, so the budget caps the whole matrix. When the last cell settles, one toast says how many succeeded and failed, with the bill when pricing is on. The grid then shows each cell ([The grid](#the-grid)).

![Studio's playground over a recorded acme-support turn, on the acme-app runtime: variant A's source run, step, system prompt, tools, model, thinking, engine, side effects and where it writes, with the option fields below them and the experiment matrix beside the variant](https://weftgo.dev/docs/_astro/studio-playground.light.C_3iakPV.webp)

*The playground: a variant's settings with the option lab under them, and the experiment matrix beside the variant.*

The name field is free text, and the experiment's id follows the command id's rule, `[A-Za-z0-9._:-]{1,128}`. A name that fits is its own id; any other is slugged with a per-page nonce, and an empty one becomes `exp_<time>`. Because of the nonce, the same odd name in another tab or after a reload makes a separate experiment; only a name that fits the rule re-runs the same one. A reopened experiment keeps its id until you rename it.

The page keeps your form as a draft in this browser (IndexedDB) once you change it, under `?exp=<draft id>`; the drafts list opens or deletes the others, and drafts never leave the browser. **copy share link** puts the whole form in the URL fragment (`#state=`, no token, at most 8,000 characters encoded): the link restores the form on any browser against the same Studio and runs nothing. A share link past 8,000 characters, or one that inflates past 256 KiB, is refused, and so is a link or draft from an older form version.

A bare `/playground` over several registered agents asks first: "Pick an agent (N registered on M runtimes) or paste a run id in Source run", with the five latest failed runs as one-click sources. A rejected or lost command offers "send again", a new command. A scripted run's card reads "scripted · 0 tokens".

## The option lab

The [option lab](https://weftgo.dev/docs/reference/glossary/#option-lab) is the form's **Options** block, one form on both surfaces: the playground page and the run page's replay drawer in Studio, and the devtools panel's experiment drawer. It has a knob for every override a command carries:

- **max steps**, **parallelism** and **temperature** (`options`);
- **top_p**, **max tokens**, **seed** and **stop (one per line)** (`params`);
- **tool choice** (`default (auto)`, any, none, named and its tool), **only tools** and **park on**;
- beside them **System prompt**, **Tools**, **Model** and **Thinking**.

Each knob shows the agent's default from `GET /api/runtimes`, greyed: the registration carries per agent `defaults` `{max_steps, parallelism, thinking, temperature?, top_p?, max_tokens?, seed?, stop?, tool_choice}`. A value that differs is drawn in colour with a `↺` back to the default. An empty knob, or one set to the default, sends nothing, so it keeps the agent's value. An agent whose registered cap is 0 has no bound, so its knob shows no default; a 0 sent as an override is refused (`max_steps must be a whole number from 1`).

The **Model** select lists the runtime's `runtime.Models` names, plus free text when the agent's runtime registered a `runtime.ModelResolver`: your app resolves the name, and its refusal is the command's reason, shown as given ([Agents and models](https://weftgo.dev/docs/observe/playground/connect/#agents-and-models)).

The form refuses a widening before it sends. It mirrors the server's rules by name: caps lower only, the ranges, a tool the agent lacks, only tools inside the tools left on, a named choice the command turns off or parks, the agent's own named default turned off. Each refusal is said on its knob in the server's words and holds Run. A tool turned off is greyed out of only tools and the named tool picker; park on lists every tool. The server stays the authority: if it refuses anyway, its 400 is shown verbatim. Both surfaces build the overrides through one function, so they post byte-identical JSON for the same choices.

The drawers pre-fill the registered system prompt and send no `instructions` override while it is unchanged, so a scripted command is not refused for an override you did not make.

A runtime older than the option lab registers no `defaults`. The form then shows the knobs with no default, and greys the seven it cannot carry (top_p, max tokens, seed, stop, tool choice, only tools, park on), saying why.

## Overrides

A command's `overrides` object, the same in a variant's `overrides`:

| Field | Values | Rule |
|---|---|---|
| `instructions` | text | replaces the system prompt; refused with the scripted engine |
| `tools_enabled` | tool names | the tools left on; each must be the agent's. An empty list, `[]`, counts as not overridden ([gotcha](#best-practices--gotchas)) |
| `model` | a name | the agent's own, a `runtime.Models` name, or one the resolver accepts; refused with the scripted engine |
| `thinking` | `off`, `low`, `medium`, `high` | neutral |
| `options.max_steps`, `options.parallelism` | a whole number from 1 | lower only |
| `options.temperature` | 0 to 2 | neutral |
| `params.top_p` | 0 to 1 | neutral |
| `params.max_tokens` | positive | neutral |
| `params.stop` | at most four non-empty strings | neutral |
| `params.seed` | any integer | neutral |
| `tool_choice` | `{"mode": "auto" \| "any" \| "none" \| "named", "name": …}` | a named choice must name a tool the command keeps on and does not park |
| `park_on` | tool names | adds parking: a parked call stops there even under `substitute` |
| `only_tools` | tool names | narrows further, inside `tools_enabled` when both are sent |

The sampling override is laid over the agent's own [`weft.Params`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Params): an absent field keeps the agent's value, and a command cannot clear the agent's `stop` or `max_tokens`. Each override is applied as a plain run option (`weft.Instructions`, `weft.OnlyTools`, `weft.UseModel`, `weft.Thinking`, `weft.MaxSteps`, `weft.Parallelism`, `weft.Params`, `weft.ToolChoice`, `weft.ParkOn`), so it shows on the run's `weft.override.*` attributes and changes its `weft.override.hash`.

Every refusal names its rule. From `TestOverrideRefusalsNameTheirRule`, against the example agent (`MaxSteps(10)`, tools `lookup_order`, `refund`, `send_email`):

| `overrides` | Status | Answer |
|---|---|---|
| `{"options":{"max_steps":50}}` | 403 | `max_steps may only lower the agent's cap` |
| `{"tools_enabled":["lookup_order"],"only_tools":["refund"]}` | 403 | `only_tools may only narrow tools_enabled: tool refund is not enabled` |
| `{"tools_enabled":["cancel_order"]}` | 400 | `tool cancel_order is not in agent acme-support's manifest` |
| `{"options":{"temperature":3}}` | 400 | `temperature must be between 0 and 2` |
| `{"params":{"top_p":1.5}}` | 400 | `top_p must be between 0 and 1` |
| `{"tool_choice":{"mode":"named","name":"refund"},"park_on":["refund"]}` | 400 | `tool_choice names refund, which park_on parks: every forced call would park` |

Each answer is the body's `error.message`, as in `{"error":{"code":"forbidden","message":"max_steps may only lower the agent's cap"}}`. With no `tool_choice` sent, an agent default naming a tool the command turns off is refused too: send `tool_choice`. The runtime checks all of it again before the ack, against its own registration, and rejects unknown engines, modes, thinking levels, options, out-of-range values, bad run or command ids and a `from_step` out of range. Against a runtime that predates the option lab, Studio refuses `params`, `tool_choice`, `park_on` and `only_tools` with 400 `runtime predates the option lab: upgrade weft/runtime to use params, tool_choice, park_on, only_tools`, since it would run the command without them.

## Saved experiments

`POST /api/experiments` creates or replaces one definition: a field it leaves out is cleared. The body is `id`, `name`, `agent`, `variants` (each `key`, `overrides`, and its own `engine`, `side_effects` or `thread` when they differ), `inputs` (each `key`, a `source_run_id` or a `text`, and its own `from_step` when it differs from the experiment's), `pass_predicate`, and the rest of the command the cells ran with: `engine`, `side_effects`, `thread`, `from_step`, `source_run_id` and `transcript_edits`. So a saved experiment reopens as the form that ran it. A negative `from_step` is refused, naming the field (`inputs[0].from_step must be a step ordinal (0 or more)`), and so is a `pass_predicate` over 4,096 bytes. It needs an id that fits `[A-Za-z0-9._:-]{1,128}` and at least one variant and one input:

```json
{"error":{"code":"bad_request","message":"an experiment defines at least one variant and one input"}}
```

`GET /api/experiments` lists the 50 most recently updated by default, `?limit=` up to 200, with `total`, the number saved:

```sh
curl -s 'http://127.0.0.1:8080/studio/api/experiments?limit=10'
```

```json
{"experiments":[{"id":"tracking-link","name":"tracking link","agent":"acme-support","variants":[{"key":"a","overrides":{}},{"key":"b","overrides":{"instructions":"You are Acme's support agent. Always include the tracking link.","options":{"temperature":0.2}}}],"inputs":[{"key":"src","source_run_id":"dd66354adfaac2b44848f0c1ed75516f"}],"engine":"live","side_effects":"substitute","thread":"ephemeral","from_step":1,"source_run_id":"dd66354adfaac2b44848f0c1ed75516f","created":"2026-10-18T10:13:09.477022685Z","updated":"2026-10-18T10:13:09.477022685Z","run_count":2,"succeeded":2,"last_run":"2026-10-18T10:13:07.374947632Z","cost_usd":0,"cost_known":true,"cost_badge":"scripted","cost_reason":"a scripted model: nothing bills it, an exact $0","cache":"exact"}],"total":1}
```

Each row is read at request time from the runs labelled with its id, never stored: `run_count` (its top-level runs), `succeeded`, `last_run` (the newest one's start; both omitted past the summary's walk cap) and the cost of its runs, own plus delegated ([See what a run cost](https://weftgo.dev/docs/observe/studio/cost/)). `GET /api/experiments/{id}` adds `runs`, the experiment's runs as run rows. `created` and `updated` keep nanoseconds.

The join is by id alone. `POST /api/playground/runs` accepts any `experiment_id`, saved or not, so a re-run sent with a saved experiment's id joins it, and a definition saved after its runs finds them all. `/api/runs` and `/api/search` take `experiment_id=` as a filter. The full request and response shapes are on [Studio's HTTP API](https://weftgo.dev/docs/reference/studio-api/).

```sh
curl -s 'http://127.0.0.1:8080/studio/api/runs?experiment_id=tracking-link' | jq -c '[.runs[] | {id, experiment_id, forked_from}]'
```

```json
[{"id":"pg_01M5780D5E5KT7515M5GAC71BS","experiment_id":"tracking-link","forked_from":"dd66354adfaac2b44848f0c1ed75516f#1"},{"id":"pg_01M5780D5BYHQNGQDWRXR84HAZ","experiment_id":"tracking-link","forked_from":"dd66354adfaac2b44848f0c1ed75516f#1"}]
```

The routes are the server token's or setup A's loopback: every panel token is refused, the reads like the write, because a definition holds prompts and inputs of any public id. A panel token's run command may not carry an `experiment_id` either.

## The experiments pages

**Experiments** in Studio's sidebar opens `/experiments` on two tabs, **matrices** and **replays**. It opens on replays when no matrix is saved.

**replays** lists every playground run, the newest 2,000 (and says so when there are more), grouped under the run it replays (its `weft.forked_from`), the group with the newest replay first. Each row is one replay: its step, what it changed (edit, prompt and model chips), its engine, its outcome, its start, and a link to compare it with its source. A replay from the drawer lands here.

**matrices** lists "the playground's saved matrices". Each row is one experiment with its agent, created, variants × inputs, engine, source run and step, runs, passed ("2 / 2 passed": its top-level runs that succeeded), last run and cost. The list shows the newest 50, says "newest N of total" when more are saved, and loads 50 more at a time up to 200. Past 200 it reads "the list stops at the newest 200" and offers no more: the API has no cursor past its `?limit=`. You can filter it by agent or source run; the filter narrows the loaded rows only.

`/experiments/{id}` draws the grid ([below](#the-grid)). From there:

![A saved experiment's page: "shorter replies" for acme-support, two variants by one input, variant A with edited instructions and variant B as registered, each cell's run succeeded at $0 · scripted](https://weftgo.dev/docs/_astro/studio-experiment.light.R11xHzvh.webp)

*A saved experiment: two variants of acme-support over one input, variant A with edited instructions, variant B as registered, each cell succeeded.*

- **re-run** one cell, or **re-run all**, under the same experiment id, each cell choosing its engine as the drawer does. When the last cell settles one toast reports the batch. With pricing on, a run not yet listed under the experiment makes the page read the experiment again, at most three times, and then the toast goes out reading "cost not read yet";
- **clone into the form**, which reopens the playground on a draft holding that form;
- pick two cells and **compare the two cells** on the compare page. Since 0.20.0 the picked cells are the URL's `?pick=<variant>×<input>,<variant>×<input>`, so a shared link opens with them picked; a third pick drops the oldest;
- "its runs in the runs list" opens `/runs` filtered by the experiment id.

`GET /api/experiments/{id}` for an id that runs carry but under which no definition was saved answers a synthetic document instead of a 404: `unsaved: true`, no variants or inputs, the agent its runs name, and its runs. The page says "no saved definition: these runs carry the experiment id, but no matrix was saved under it". An id with no runs is still a 404.

Under a panel token, Experiments is not offered in the sidebar, the ⌘K palette or the playground's history; opened by URL, the page shows the hidden badge ("dev token only") and fetches nothing.

## The grid

The grid has one row per input, one column per variant, and a source column naming the run each row's cells replay and the step. Each cell is its latest run, in one line: outcome · the answer's first line (at most 80 characters, "no answer text" when the run produced none) · tokens · cost · engine (`scripted`, or `live · <model>`) · its wall time, with the run id's tail (`…VGKSMX`) and a link to compare it with its source.

Each cell also reads a chip against its source: "same as source", "same where both recorded", or "changed at step N", from one `GET /api/diff` per cell, aligned on the source's steps ([Replays align on their source](https://weftgo.dev/docs/observe/studio/compare/#replays-align-on-their-source)). Only the grid's first 24 cells read it; a later cell links to the compare and says it was not read.

A matrix Studio has issued opens as `/experiments/<id>?issued=N`: the grid reads the experiment again until N top-level runs joined (a subagent's child run that carries the experiment id is no cell), for at most two minutes. Meanwhile its empty cells read "issued, not started" and the summary waits. Past two minutes it says "k issued cells never started (no run joined in 2 minutes): counted as missing".

## Pass predicate

A matrix carries a pass predicate, and the grid judges each cell's latest run with it: **✓ pass**, **✗ fail** or **? not judged**, with the reason. The language is clauses joined by `AND`:

| Clause | Reads |
|---|---|
| `status = <word>`, `status != <word>` | the run's status: `succeeded`, `failed`, `interrupted`, `running` |
| `answer ~ /re/flags`, `answer !~ /re/flags` | the run's last answer against a JavaScript regular expression, flags `i`, `m`, `s`, `u` |
| `answer = "text"`, `answer != "text"` | the whole answer, exactly |
| `steps`, `tokens` or `cost` with `<`, `<=`, `=`, `>=`, `>` and a number | the step count, input + output tokens, the whole bill in USD (own + delegated) |

An empty predicate is `status = succeeded`. For example:

```text
status = succeeded AND answer ~ /tracking/i AND cost < 0.01
```

A fact the predicate reads that is not known is never a pass and never an empty answer: an answer not read yet, content off, stripped or unreadable, or an unpriced cost makes the cell not judged. A known fail wins over an unknown one. The grid reads the answer for every cell of the first 20 rows and says so past them.

An `answer ~` pattern is tested off the page, on the answer's first 8 KiB. A pattern that can take exponential time (an unboundedly repeated group that itself holds an unbounded quantifier, or a backreference) is refused when you type it; any other runs in a worker, bounded at 250 ms per answer, and past that the cell is not judged.

Under the grid each column gets its tally, "5/7 · $0.0021", or "3/4 judged" while some cells are not judged. The summary names the cheapest column whose every row passed and the cheapest column overall, never a column with rows missing; while any cell is not judged it says "k cells not judged: no cheapest yet" with the reason. A bill that is not known reads "unpriced" for a model with no price, else "cost unknown". You can try a predicate on the grid and save it on the definition.

The predicate is Studio's alone: `POST /api/experiments` stores `pass_predicate` verbatim, at most 4,096 bytes, and the server validates nothing in it and judges no cell.

## A matrix from a failure class

The runs list groups failures into error classes ([Error classes](https://weftgo.dev/docs/observe/studio/stats/#error-classes)). With one class picked, **Experiment on these N →** opens the playground's multi-source matrix over those runs, one matrix per agent: `/playground?sources=<ids>&agent=<name>`, at most 20 source runs, said when the class holds more.

- **Rows** are the source runs, each continuing from its own failing step: the step its error names ("run failed at step N"), else its last recorded step, with its own kept prefix.
- **Columns** are models: the agent's models, each on live, or the agent's own on scripted ("scripted replays the recording: only the agent's own model can run on it").
- **A pass predicate**, as above.
- **The estimate before Run**: "28 cells · ≈ 34k tokens · ≈ $0.012", with each column's figure, from the source steps' recorded usage priced at each column's model under Studio's price table. An unpriced model reads "cost unknown: `<model>` has no price", never $0. A failed source is a floor, "≥", and a failing step that billed nothing is estimated at the step before's input tokens, said in a note.

**Run matrix** saves one experiment (each input its `source_run_id` and its own `from_step`, the predicate verbatim), issues every cell through the grid's own cell rule, and links the grid with the count it sent. The playground holds Run while no connected runtime registers the agent ([Runs in](https://weftgo.dev/docs/observe/playground/runtimes/#runs-in)).

## Budgets

[`runtime.Budget`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Budget) caps one experiment, counted per `experiment_id` from the usage of the commands this runtime ran. Pass it with `runtime.Limits` at Install ([Connect your app](https://weftgo.dev/docs/observe/playground/connect/#install)):

| Field | Caps |
|---|---|
| [`MaxTokensPerExperiment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Budget.MaxTokensPerExperiment) | input + output tokens across the experiment's runs |
| [`MaxRunsPerExperiment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Budget.MaxRunsPerExperiment) | the number of commands run, reserved at admission |

A zero field is no cap; without `Limits` a runtime accepts unlimited playground runs within the agent's own budgets (`MaxSteps`, `UsageLimit`). A breach rejects a command of that experiment before its ack,  never a run in flight and never your app's own runs. The run cap is exact: each command reserves its run at admission and gives the reservation back when it never ran, so the cap's last command is the last one run. The token cap is counted from usage after a run ends, so the run that crosses it finishes and the next command is rejected. Budgets count failed runs and every leg of a substitute chain (the chain's resumed runs). With `MaxRunsPerExperiment: 2`, the third command's row from `TestBudgetRefusesTheNextCommand`:

```json
{"command_id":"cmd_budget_3","state":"rejected","run_id":"","error":"budget_exceeded","created":"2026-10-18T11:39:18.426637411+02:00","updated":"2026-10-18T11:39:18.426764993+02:00"}
```

The tally lives in the runtime's memory, one per `runtime.Install`: an app restart, each `weft dev` reload on save included, starts every experiment's count again at zero, and two processes serving the same agents count separately. A command with no `experiment_id` counts against no experiment's cap. The matrix sends every cell under its experiment's id, so the cap covers the whole matrix.

## Complete example

Start the example program from [How does the playground work?](https://weftgo.dev/docs/observe/playground/overview/#complete-example) open the playground on its source run, and press **Run matrix**:

```sh
go run ./playground
```

```text
playground: http://127.0.0.1:8080/studio/playground
source run: dd66354adfaac2b44848f0c1ed75516f
```

The tests `TestOverrideRefusalsNameTheirRule` and `TestBudgetRefusesTheNextCommand` in [`main_test.go`](https://github.com/weftgo/weftgo.dev/blob/main/docs-site/examples/playground/main_test.go) send the refused commands above, the resolver's refusal and acceptance, and three commands under `MaxRunsPerExperiment: 2`.

## Best practices & gotchas

- **Name an experiment within `[A-Za-z0-9._:-]` to re-run the same one.** Any other name is slugged with a per-page nonce, so it starts a new experiment each time. (Source: `studio/README.md:1854-1860`)
- **A hand-written `POST /api/experiments` is not held to the variant-name rules.** They are checked in the browser only; the server checks the id, the modes, the overrides' shape and `from_step`. (Source: `studio/web/src/routes/playground.tsx:493-504`; `studio/experiments.go:120-170`)
- **Leave a knob empty to keep the agent's value.** An empty knob sends nothing; a command cannot clear the agent's `stop` or `max_tokens`. (Source: `studio/README.md:1703-1705`)
- **A command cannot turn every tool off.** With `tools_enabled` and `only_tools` both empty or absent, the run gets every tool; an empty `only_tools` beside a non-empty `tools_enabled` narrows to `tools_enabled`. With every tool unticked, the form and the panel drawer issue nothing and show `at least one tool must stay on — the command cannot express an empty tool set (it would run with every tool)`. To test an agent with no tools, keep one harmless tool on. (Source: `studio/web/src/lib/experiment-body.ts:153-163`; `routes/playground.tsx:1306-1309`; `panel/playground.ts:289-291`; `studio/playground.go:916-926`; `runtime/executor.go:1376-1382`)
- **Keep `submit_output` on for an `Output[T]` agent.** `tools_enabled` and `only_tools` both run as `weft.OnlyTools`, which drops a tool the list leaves out, `submit_output` included. The run then ends without a value: the model's submission reads `NO_SUCH_TOOL: no tool named "submit_output"`. List it in the override; it is in the agent's manifest, so Studio accepts the name. (Source: `runtime/executor.go:1374-1382`; `core/agent.go:1013-1028`; `core/manifest.go:180-191`; `studio/playground.go:703-713`)
- **Without `runtime.Limits` a matrix is uncapped.** The default accepts unlimited playground runs, so the only caps are the agent's own `MaxSteps` and `UsageLimit`. (Source: `runtime/options.go:131-136`)
- **Do not treat a budget as a lifetime cap.** It counts what this process ran since `runtime.Install`. Under `weft dev`, every save restarts the app and resets the count, so a matrix re-run after an edit gets the whole budget again. (Source: `runtime/link.go:106, 137`; `runtime/options.go:336`; `runtime/executor.go:573-581`)
- **Expect the token cap to bite one command late.** The run that crosses `MaxTokensPerExperiment` finishes; `MaxRunsPerExperiment` is exact. (Source: `runtime.Budget` godoc; `runtime/executor.go:588-600`)
- **Use the dev token for experiments.** Every panel token is refused on the experiments routes. (Source: `studio/experiments.go`)
- **Write the predicate for what you need to be true, not only `succeeded`.** A run that succeeded with the wrong answer passes the default. Add an `answer ~` or a `cost <` clause. (Source: `lib/predicate.ts` `DEFAULT_PREDICATE`)
- **Record with content on to judge answers.** With content off the answer is not known, so every `answer` clause leaves the cell not judged. (Source: `lib/predicate.ts`, `lib/experiments.ts` `answerText`)

## See also

- [Replay a run from any step, with edits](https://weftgo.dev/docs/observe/playground/replay/)
- [How does the playground work?](https://weftgo.dev/docs/observe/playground/overview/)
- [Compare runs step by step](https://weftgo.dev/docs/observe/studio/compare/)
- [See what a run cost](https://weftgo.dev/docs/observe/studio/cost/)
- [How does a run stop?](https://weftgo.dev/docs/concepts/budgets-and-stopping/)

Symbols used: [`runtime.Limits`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Limits) · [`runtime.Budget`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Budget) · [`Budget.MaxTokensPerExperiment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Budget.MaxTokensPerExperiment) · [`Budget.MaxRunsPerExperiment`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Budget.MaxRunsPerExperiment) · [`runtime.Models`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#Models) · [`runtime.ModelResolver`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/runtime#ModelResolver) · [`weft.Params`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#Params) · [`weft.ToolChoice`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ToolChoice) · [`weft.ParkOn`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#ParkOn) · [`weft.OnlyTools`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#OnlyTools) · [`weft.UseModel`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2#UseModel)
