> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withwhile.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Install with `uv add whileai`; import as `import whileai as wai`.
> Run the offline path first (`simulator=False`, `wai.seeded_agent`, a callable judge); no key is needed for it.
> Report every pass rate with its interval and n, as `scored.pass_at` prints it.

# Recipes

> One post-training run as five steps, each step a runnable, self-contained recipe: what you learn, what you need, how long it takes.

34 runnable recipes, one directory each. Every recipe says what you
learn, what it needs and how long it takes, and its first command runs the
whole thing. Anything marked offline needs no key and no network.

Read them in order the first time. After that, jump to the step you are on.

<Note>
  The scripts live in the repository, not in the installed package. Clone it
  first: `git clone https://github.com/whilehq/whileai-sdk.git`, then `cd` to the recipe
  directory named at the top of its page.
</Note>

## Simulate

Make rollouts: an agent, situations, a reward that is a program.

<CardGroup cols={2}>
  <Card title="bring-your-own-agent" href="/recipes/01-simulate/bring-your-own-agent">
    the `agent(message) -> {steps, final_text}` contract, what a run says when the agent raises, why an `evaluate()` score must not become the reward
  </Card>

  <Card title="verifiers" href="/recipes/01-simulate/verifiers">
    rewards that are programs: `MathEqual`, `All` (answer and format), `CodeExec` against hidden tests, `JSONSchema`, each honoring the judge contract
  </Card>
</CardGroup>

## Measure

Say what the numbers mean: pass\@k, headroom, reward hacking, safety.

<CardGroup cols={2}>
  <Card title="compare-judges" href="/recipes/02-measure/compare-judges">
    six judges on the same 300 labeled rollouts, one ranked table: agreement with its interval, kappa, leak rate, unsure and unjudged counts, seconds per row; Jev, the hosted judge, Claude, and the policy judging itself
  </Card>

  <Card title="eval-your-agent" href="/recipes/02-measure/eval-your-agent">
    evals for the agent you already have: wrap it, write the policy as a judge, pass\@1 with an interval per policy branch, the coverage warnings that catch a hollow run, a CI gate
  </Card>

  <Card title="is-your-eval-any-good" href="/recipes/02-measure/is-your-eval-any-good">
    whether a number your eval produced means anything: ceiling, headroom, criteria that cannot fail, self-noise, the judge, contamination, and the three checks that void a base-vs-tuned comparison outright
  </Card>

  <Card title="pass-at-k" href="/recipes/02-measure/pass-at-k">
    pass\@1 with its interval, pass^k, pass\@k, the per-ask histogram the mean hides, and headroom = what a grouped update can learn
  </Card>

  <Card title="reward-hacking" href="/recipes/02-measure/reward-hacking">
    reward hacking caught before, during and after training: the within-ask scan, the judge probes, the trajectory flags, the proxy-vs-target verdict
  </Card>

  <Card title="safety-evals" href="/recipes/02-measure/safety-evals">
    a safety suite for a tool-using agent: prompt injection, exfiltration, secret leakage, unauthorized writes, benign controls; four trajectory markers as the judge, pass^k per attack class, a before/after that fails the fix which got safe by refusing
  </Card>

  <Card title="safety-evals-marketplace" href="/recipes/02-measure/safety-evals-marketplace">
    the same eval where the untrusted text is user-generated content and the private data is per tenant; `live.py` runs it on a local model through Ollama
  </Card>
</CardGroup>

## Select

Turn graded rows into training data: SFT rows, pairs, RL groups.

<CardGroup cols={2}>
  <Card title="character" href="/recipes/03-select/character">
    a constitution to traits, graded replies per trait, a judge checked against the spec's own labels, length-matched pairs and masked SFT rows, before/after on an adversarial holdout
  </Card>

  <Card title="prime-intellect-rl" href="/recipes/03-select/prime-intellect-rl">
    `simulate(mode="rl")` for uniform groups, the gradient gate (`diagnose.py`) that catches a reward the policy can game before you train, prompts in the `verifiers` shape
  </Card>

  <Card title="schema" href="/recipes/03-select/schema">
    one row file projected into eval, SFT, preference, GRPO prompts, OPSD and OPD targets; the `Task`/`Rollout`/`Judgment`/`Marker` split that makes that possible
  </Card>
</CardGroup>

## Train

Train it, hosted or on your own GPU, and watch the run page.

<CardGroup cols={2}>
  <Card title="dpo" href="/recipes/04-train/dpo">
    on-policy pairs from `build_preference_pairs`, TRL `DPOTrainer`, the reward margin on the run page, iterated rounds with `--from-run`, constructed negatives
  </Card>

  <Card title="grpo" href="/recipes/04-train/grpo">
    TRL `GRPOTrainer` with LoRA on a verifiable rule, `HackMonitor` and reward/KL on the run page, paired pass\@1 before/after with per-category deltas, loss variants and `--balance` as flags
  </Card>

  <Card title="hosted-loop" href="/recipes/04-train/hosted-loop">
    push graded rows, `wai.train` SFT on Qwen3-4B, `wai.serve` the adapter, one chat completion from the endpoint
  </Card>

  <Card title="identity" href="/recipes/04-train/identity">
    a leak-free SFT set that teaches a name and maker, with Modal scripts for the LoRA and for the identity/leak eval
  </Card>

  <Card title="prime-rl" href="/recipes/04-train/prime-rl">
    GRPO, OPSD and OPD on one taskset on prime-rl from `wai.prime_rl_config`, a launcher over Prime Intellect's published image, per-prompt held-out deltas with intervals from `wai.compare`; run e2e1: OPD matched GRPO with no reward, OPSD moved a fifth as far
  </Card>

  <Card title="report-run" href="/recipes/04-train/report-run">
    the typed objects the platform tracks (a tracked agent with its harness, behaviors, runs, live traffic), why a harness is versioned by its fingerprint, and why a version is scored on every behavior
  </Card>

  <Card title="resist-planted-instruction" href="/recipes/04-train/resist-planted-instruction">
    a behaviour rubric decided by code, the criterion promoted into the reward on probe evidence, rejection sampling from the base itself, a pre-registered random-selection control, three arms from one vLLM process with attack and clean halves apart
  </Card>

  <Card title="text-to-sql" href="/recipes/04-train/text-to-sql">
    hill-climb a model on a schema with a verifier as the reward: a seeded Postgres, 741 execution-checked tasks, `SQLExec`, benchmarks through `simulate(tasks=)`, self-distillation, GRPO rounds on Modal with vLLM generation and Postgres in the container, every round measured on the same holdout
  </Card>
</CardGroup>

## Export

Ship the data and the adapter.

<CardGroup cols={2}>
  <Card title="hugging-face" href="/recipes/05-export/hugging-face">
    rows to a Hub dataset repo (one split per purpose, commit tagged by dataset id), any Hub split onto the account with a profile, a run's adapter to a model repo
  </Card>
</CardGroup>

## Papers

One directory per paper.

<CardGroup cols={2}>
  <Card title="adaptive-clip" href="/recipes/papers/adaptive-clip">
    Paper: Group Adaptive Clipping Policy Optimization, Sheng Jia et al., arXiv:2609.00444, August 2026.
  </Card>

  <Card title="endpoint-sft" href="/recipes/papers/endpoint-sft">
    Paper: Revisiting Complete Reasoning Traces for Post-Training, Jaehui Hwang et al., arXiv:2609.07103, September 2026.
  </Card>

  <Card title="filter-metric" href="/recipes/papers/filter-metric">
    Paper: The Filter Metric is Safety-Critical: Phantom Advantages in Group-Relative RL under Shaped Rewards, Juntao Yu, arXiv:2609.13866, September 2026.
  </Card>

  <Card title="gmts-token-select" href="/recipes/papers/gmts-token-select">
    Paper: GMTS: Gradient Magnitude-based Token Selection Improves RLVR Training, Outongyi Lv et al., arXiv:2608.30632, August 2026.
  </Card>

  <Card title="zero-rl-format-reward" href="/recipes/papers/zero-rl-format-reward">
    Paper: SimpleRL-Zoo: Investigating and Taming Zero Reinforcement Learning for Open Base Models in the Wild, Weihao Zeng et al., arXiv:2503.18892, March 2025.
  </Card>
</CardGroup>

## Community

Recipes contributed by people trying the SDK on their own problems, published so the next person starts from someone's real run instead of from zero.

<CardGroup cols={2}>
  <Card title="can-the-judge-be-trusted" href="/recipes/community/can-the-judge-be-trusted">
    Grade the same rollouts two ways — with rubric\_judge() and with a deterministic verifier — and measure where the LLM judge disagrees with the rule.
  </Card>

  <Card title="force-the-branch" href="/recipes/community/force-the-branch">
    Seat: a post-training engineer at a startup that ships one production agent, trying to find out whether a small open model can take over the boring half of it.
  </Card>

  <Card title="hosted-grpo-vs-sft" href="/recipes/community/hosted-grpo-vs-sft">
    Seat: an open-model fine-tuner who lives in TRL and Hugging Face, here for clean exports, a LoRA run, a hosted result and a cost line.
  </Card>

  <Card title="how-much-contamination-survives" href="/recipes/community/how-much-contamination-survives">
    Measure what fraction of real held-out contamination wai.decontaminate() actually removes, using human-labelled paraphrase pairs as ground truth instead of a planted copy.
  </Card>

  <Card title="same-entrypoint-before-after" href="/recipes/community/same-entrypoint-before-after">
    Seat: a post-training engineer at a startup that ships one production agent, trying to find out whether a small open model can take over the boring half of it.
  </Card>

  <Card title="the-step-the-course-skips" href="/recipes/community/the-step-the-course-skips">
    The eight-lesson course for people who have never trained a model stops one line short of the training: # 2.
  </Card>

  <Card title="what-trl-does-with-the-loss-mask" href="/recipes/community/what-trl-does-with-the-loss-mask">
    wai.export(..., format="trl") writes a loss\_mask on every row and reports mask\_mode: "assistant".
  </Card>

  <Card title="who-protects-the-holdout" href="/recipes/community/who-protects-the-holdout">
    decontaminate() applies four rules in order.
  </Card>
</CardGroup>

## Write one

Copy [`recipes/_template`](https://github.com/whilehq/whileai-sdk/tree/main/recipes/_template) into the step it belongs
to, replace the parts in angle brackets, and open a pull request. The contract is in
[CONTRIBUTING.md](https://github.com/whilehq/whileai-sdk/blob/main/CONTRIBUTING.md#contributing-a-recipe).
