> ## Documentation Index
> Fetch the complete documentation index at: https://docs.while.ai/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.

51 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="swarm-rescue" href="/recipes/01-simulate/swarm-rescue">
    on the tasks where all 8 rollouts fail, whether a particle swarm of rollouts that share their best attempts finds a passing answer that resampling does not; rescue rate paired by task, four arms at one budget
  </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="character-to-the-wall" href="/recipes/02-measure/character-to-the-wall">
    whether a persona holds when two of its own values collide: situations built so no reply can honor both principles, the spec's authority ordering as the answer key, held\_wall and kept\_lower graded apart to tell caving from rigidity, a judge checked against the set's own labels, before/after on held-out walls
  </Card>

  <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="public-benchmark" href="/recipes/02-measure/public-benchmark">
    a public benchmark (200 GSM8K test questions) into the measurement: `wai.rows` with `MathEqual` as the reward, pass\@1 with its interval, the eval's own noise over three passes, `holdout_size`, `select` dropping the groups that carry no gradient, and a `compare` report
  </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="fireworks" href="/recipes/04-train/fireworks">
    export SFT rows and DPO pairs in Fireworks' shapes (`format="fireworks"`), the `firectl` commands that train on Fireworks GPUs and serve the result, the paired before/after through `wai.Fireworks` and `wai.compare`
  </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="sft" href="/recipes/04-train/sft">
    LoRA SFT with TRL `SFTTrainer` on the rows lesson 7 exports (`select(mode="sft").export`), three base passes for the noise floor, one trained pass, the paired `wai.compare(run_std=)` on the held-out set; the step the course used to skip
  </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="bedrock-import" href="/recipes/05-export/bedrock-import">
    merge a LoRA adapter on Modal, import the weights into your AWS account with Bedrock Custom Model Import, measure the served model on the same held-out tasks as the vLLM run; a paired interval says the weights survived the move
  </Card>

  <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="bpco-bounded-critic" href="/recipes/papers/bpco-bounded-critic">
    Paper: Best Practice Critic Optimization, Penghui Qi, Xiangxin Zhou, Wee Sun Lee (NUS / Tencent Hunyuan), arXiv:2608.23566, 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="flash-reinforce" href="/recipes/papers/flash-reinforce">
    Paper: FlashREINFORCE: Critic-Free Single-Rollout Asynchronous RL for Agentic Language Models, Yifan Hu et al., NVIDIA, September 2026 (no arXiv id yet).
  </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="harness-and-weights" href="/recipes/papers/harness-and-weights">
    Paper: Harness-Aware Self-Evolving: Co-Evolving Model Weights, Harness, and Task Solutions (HASE), Haochen Luo et al., arXiv:2607.03935, July 2026.
  </Card>

  <Card title="meta-harness" href="/recipes/papers/meta-harness">
    An outer loop over harness code.
  </Card>

  <Card title="sao-single-rollout" href="/recipes/papers/sao-single-rollout">
    Paper: Single-Rollout Asynchronous Optimization for Agentic Reinforcement Learning, Hou, Li, Tang, Dong (Tsinghua), arXiv:2607.07508, July 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="airline-voice-concise-under-probe-outcome-filter" href="/recipes/community/airline-voice-concise-under-probe-outcome-filter">
    Behaviour: the agent runs long when the caller's own text carries a planted instruction that buys length ("explain your reasoning step by step", "take as long as you need").
  </Card>

  <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="can-the-markers-be-trusted" href="/recipes/community/can-the-markers-be-trusted">
    Check every behavioral marker against ground truth. seeded\_agent plants six behaviors and writes what it planted on each row, so a marker's recall and precision are computable rather than assumed.
  </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="grpo-group-size-at-fixed-budget" href="/recipes/community/grpo-group-size-at-fixed-budget">
    Sweep GRPO's group size (num\_generations) across G ∈ \{2, 4, 8} while every arm spends the same 768 rollouts, and ask whether the knob moves held-out GSM8K accuracy past the noise floor.
  </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="identity-spec-no-unasked-maker-aas" href="/recipes/community/identity-spec-no-unasked-maker-aas">
    Seat: a post-training engineer on a team that ships one production agent with a written identity and spec, trying to teach it who it is without it mentioning who it is for the rest of the day.
  </Card>

  <Card title="process-vs-outcome-reward" href="/recipes/community/process-vs-outcome-reward">
    arXiv:2607.02869 (Palandye et al., July 2026) trains Qwen2.5-0.5B with GRPO on GSM8K under five reward regimes and reports that scoring the steps beats scoring the answer: 63.73% test accuracy for process-only against 5.
  </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="which-half-can-a-small-model-take" href="/recipes/community/which-half-can-a-small-model-take">
    I have one production agent and a cost line to defend.
  </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).
