Track Experiments with W&B
Instrument an experiment loop so every candidate becomes a comparable W&B run with enough context to understand what changed, what happened, and whether the objective improved.
Operating Rules
- Treat W&B as an observation layer. The experiment loop, including a Ralph loop, must continue making decisions from local results rather than a required round trip to W&B.
- Use one W&B run per candidate experiment, not one long run for the entire research session.
- Use a shared run
group to connect iterations from the same experiment session.
- Keep
config for independent variables and provenance, run.log() for changing measurements, and run.summary for final comparison values.
- Preserve the existing experiment command, objective calculation, retry behavior, and stopping logic.
- Prefer structured IDs and short summaries over full prompts, source files, or large generated outputs.
- Keep live alerts disabled until Scriptable run alerts and a destination are configured.
- Verify exact SDK and alert behavior against current official W&B documentation before implementing brittle details.
- Use W&B Models for experiments and system metrics; use
weave-add-tracing for model, agent, and tool traces.
Workflow
1. Find the Research Loop Contract
Identify:
- The experiment loop controller and candidate entrypoint.
- The unit that represents one iteration or candidate.
- The primary objective name, value, and
maximize or minimize direction.
- Baseline value or baseline run, if one exists.
- Iteration, time, cost, and retry budgets.
- Where hypothesis, code change, seed, dataset, command, and result are already represented.
Read references/experiment-tracking-patterns.md before changing code.
2. Define the Run Contract
Default lifecycle:
Experiment session
|- candidate iteration 0 -> W&B run
|- candidate iteration 1 -> W&B run
`- candidate iteration 2 -> W&B run
Use these W&B fields consistently:
project: the research problem or comparison boundary.
group: stable experiment session ID.
job_type: research-iteration unless the repository already uses a taxonomy.
name: iteration plus a short hypothesis or candidate ID.
tags: optional baseline, candidate, ablation, or failure category.
notes: a concise human-readable hypothesis or change summary.
Recommended config keys:
session_id, iteration, candidate_id, parent_run_id
hypothesis_id, change_id, code_revision
objective_name, objective_direction, baseline_run_id
dataset_id, seed, experiment_command
iteration_budget, time_budget_sec, cost_budget_usd
3. Add Minimal Logging
- Wrap each candidate lifecycle in one
wandb.init() context.
- Pass immutable experiment inputs and provenance in
config.
- Log step or epoch metrics next to the code that produces them.
- Finalize comparison fields once in
run.summary.
- Allow exceptions to propagate through the run context so failed experiments remain failed locally and in W&B.
- Enable W&B code saving when permitted so git state and a working-tree diff can support reproduction.
Recommended metric shape:
objective/value
train/loss, eval/loss, or domain metrics already produced by the experiment
ops/duration_sec, ops/cost_usd, ops/exit_code
loop/iteration, loop/stagnation_count
Recommended summary shape:
objective/final, objective/best
objective/delta_from_baseline, objective/improved
ops/duration_sec, ops/cost_usd, ops/exit_code, ops/status
Do not invent metrics the experiment cannot compute reliably.
4. Add Guarded Alerts
Make alert enablement explicit, such as WANDB_ENABLE_ALERTS=1. Keep it off by default.
Start with a few actionable conditions:
- experiment process exits unsuccessfully;
- objective is missing or non-finite;
- time or cost budget is exceeded;
- the loop reaches its configured stagnation limit;
- optional final notification when the research session completes.
Use a cooldown for repeated conditions. Do not alert on every ordinary metric fluctuation or every successful iteration.
5. Validate One Iteration
- Run formatting, static checks, and focused tests.
- Execute one baseline or cheap smoke candidate when credentials and resources permit.
- Confirm exactly one new W&B run appears for that candidate.
- Check group, config, metric history, summary, status, logs, and code provenance.
- Confirm alerts remain dry unless explicitly enabled.
- Report the run URL and the exact expected schema when a live run is not possible.
- Hand analysis of recorded runs to
wandb-project-analyst and W&B MCP.
Hands-on
Use skills/wandb/hands-on/handson_models.ipynb for a short introduction to one run, config, metric logging, summary, and a guarded scriptable alert.
Run its single code cell once. Keep SEND_ALERT=False until the user confirms that alert delivery is configured.
References
- Read
references/experiment-tracking-patterns.md for the run lifecycle, code shape, alert guards, and validation checklist.
- Use the official wandb/skills repository for broad W&B SDK and project-analysis patterns; keep this skill focused on experiment instrumentation.
Response Shape
Return:
- The experiment session and candidate run contract.
- Config, metric, and summary schema.
- Changed files and lifecycle insertion points.
- Guarded alert conditions.
- Validation performed and expected W&B behavior.
1---2name: wandb-track-experiment3description: Add W&B Models experiment tracking and guarded alerts to iterative experiment workflows, including Codex or Ralph-loop autoresearch. Use when the user asks to instrument experiments, create one W&B run per candidate, group related runs, record hypotheses and code provenance, log metrics and summaries, detect failed or stalled experiments, or validate that runs are comparable and reproducible. Use wandb-project-analyst for analysis of data already stored in W&B.4---56# Track Experiments with W&B78Instrument an experiment loop so every candidate becomes a comparable W&B run with enough context to understand what changed, what happened, and whether the objective improved.910## Operating Rules1112- Treat W&B as an observation layer. The experiment loop, including a Ralph loop, must continue making decisions from local results rather than a required round trip to W&B.13- Use one W&B run per candidate experiment, not one long run for the entire research session.14- Use a shared run `group` to connect iterations from the same experiment session.15- Keep `config` for independent variables and provenance, `run.log()` for changing measurements, and `run.summary` for final comparison values.16- Preserve the existing experiment command, objective calculation, retry behavior, and stopping logic.17- Prefer structured IDs and short summaries over full prompts, source files, or large generated outputs.18- Keep live alerts disabled until Scriptable run alerts and a destination are configured.19- Verify exact SDK and alert behavior against current official W&B documentation before implementing brittle details.20- Use W&B Models for experiments and system metrics; use `weave-add-tracing` for model, agent, and tool traces.2122## Workflow2324### 1. Find the Research Loop Contract2526Identify:27281. The experiment loop controller and candidate entrypoint.292. The unit that represents one iteration or candidate.303. The primary objective name, value, and `maximize` or `minimize` direction.314. Baseline value or baseline run, if one exists.325. Iteration, time, cost, and retry budgets.336. Where hypothesis, code change, seed, dataset, command, and result are already represented.3435Read `references/experiment-tracking-patterns.md` before changing code.3637### 2. Define the Run Contract3839Default lifecycle:4041```text42Experiment session43|- candidate iteration 0 -> W&B run44|- candidate iteration 1 -> W&B run45`- candidate iteration 2 -> W&B run46```4748Use these W&B fields consistently:4950- `project`: the research problem or comparison boundary.51- `group`: stable experiment session ID.52- `job_type`: `research-iteration` unless the repository already uses a taxonomy.53- `name`: iteration plus a short hypothesis or candidate ID.54- `tags`: optional `baseline`, `candidate`, `ablation`, or failure category.55- `notes`: a concise human-readable hypothesis or change summary.5657Recommended config keys:5859- `session_id`, `iteration`, `candidate_id`, `parent_run_id`60- `hypothesis_id`, `change_id`, `code_revision`61- `objective_name`, `objective_direction`, `baseline_run_id`62- `dataset_id`, `seed`, `experiment_command`63- `iteration_budget`, `time_budget_sec`, `cost_budget_usd`6465### 3. Add Minimal Logging66671. Wrap each candidate lifecycle in one `wandb.init()` context.682. Pass immutable experiment inputs and provenance in `config`.693. Log step or epoch metrics next to the code that produces them.704. Finalize comparison fields once in `run.summary`.715. Allow exceptions to propagate through the run context so failed experiments remain failed locally and in W&B.726. Enable W&B code saving when permitted so git state and a working-tree diff can support reproduction.7374Recommended metric shape:7576- `objective/value`77- `train/loss`, `eval/loss`, or domain metrics already produced by the experiment78- `ops/duration_sec`, `ops/cost_usd`, `ops/exit_code`79- `loop/iteration`, `loop/stagnation_count`8081Recommended summary shape:8283- `objective/final`, `objective/best`84- `objective/delta_from_baseline`, `objective/improved`85- `ops/duration_sec`, `ops/cost_usd`, `ops/exit_code`, `ops/status`8687Do not invent metrics the experiment cannot compute reliably.8889### 4. Add Guarded Alerts9091Make alert enablement explicit, such as `WANDB_ENABLE_ALERTS=1`. Keep it off by default.9293Start with a few actionable conditions:9495- experiment process exits unsuccessfully;96- objective is missing or non-finite;97- time or cost budget is exceeded;98- the loop reaches its configured stagnation limit;99- optional final notification when the research session completes.100101Use a cooldown for repeated conditions. Do not alert on every ordinary metric fluctuation or every successful iteration.102103### 5. Validate One Iteration1041051. Run formatting, static checks, and focused tests.1062. Execute one baseline or cheap smoke candidate when credentials and resources permit.1073. Confirm exactly one new W&B run appears for that candidate.1084. Check group, config, metric history, summary, status, logs, and code provenance.1095. Confirm alerts remain dry unless explicitly enabled.1106. Report the run URL and the exact expected schema when a live run is not possible.1117. Hand analysis of recorded runs to `wandb-project-analyst` and W&B MCP.112113## Hands-on114115Use `skills/wandb/hands-on/handson_models.ipynb` for a short introduction to one run, config, metric logging, summary, and a guarded scriptable alert.116117Run its single code cell once. Keep `SEND_ALERT=False` until the user confirms that alert delivery is configured.118119## References120121- Read `references/experiment-tracking-patterns.md` for the run lifecycle, code shape, alert guards, and validation checklist.122- Use the official [wandb/skills](https://github.com/wandb/skills) repository for broad W&B SDK and project-analysis patterns; keep this skill focused on experiment instrumentation.123124## Response Shape125126Return:1271281. The experiment session and candidate run contract.1292. Config, metric, and summary schema.1303. Changed files and lifecycle insertion points.1314. Guarded alert conditions.1325. Validation performed and expected W&B behavior.