Optimize Workload
Use this worker only after the workload has fresh local artifacts from
capture-evidence. Validation and optimization must be evidence-led and
split-safe.
Safety Gates
Default to the intervention with the highest expected progress toward the
objective under hard constraints, not the cheapest rung. State the expected
quality gain, time, spend envelope, and evidence before execution; follow
../understudy/reference.md → Outcome-first spend
posture. A developer action that launches a named bounded optimization plan
authorizes its declared model calls, uploads, hosted work, evaluation, receipts,
and cleanup. Do not pause for phase-by-phase confirmation. Ask again only if the
plan expands its displayed data, destination, spend, retention, download, or
production-impact envelope. Follow the repo public boundary in
../../docs/privacy-and-data-boundaries.md
for prompts, completions, traces, labels, datasets, repo paths, secrets, and
private notes.
Refusal Gate
Refuse to optimize unless all required artifacts are present and fresh:
.understudy/capture-evidence/harness.json
.understudy/capture-evidence/metric.json
.understudy/capture-evidence/splits.json
.understudy/capture-evidence/baseline.json
Fresh means generated for the same workload, metric, split contract, and
incumbent baseline in the current task context. Freshness is hash-bound:
baseline.json must include harness_sha256, metric_sha256, and
splits_sha256, and those values must match the current harness.json,
metric.json, and splits.json. If freshness is ambiguous or hashes do not
match, route back to
../capture-evidence/SKILL.md instead
of optimizing.
Split Rules
- GEPA is train/dev-only.
- Prompt, route, parser, renderer, and candidate selection changes may use
train and dev only.
- Never mutate holdout rows, labels, validators, thresholds, or sampling after
optimization begins.
- Holdout is only for final validation after the candidate is frozen.
- If holdout is touched accidentally, mark the result contaminated and create a
new split contract before claiming progress.
Before You Optimize
Confirm these before spending GEPA budget — full detail, model defaults, and
validator kinds in reference.md:
Evidence gates — apply the coverage, harness-conformance, qualitative
row-review, and claim-strength gates in
../capture-evidence/references/evaluation-evidence-gates.md.
Do not optimize a narrow easy cohort as though it represents the workload.
Inspect the real rows behind the baseline headline and confirm important hard
strata have train/dev and sealed-holdout representation. Treat a small pilot
as a plumbing check only; if uncertainty, variance, or new failure classes
remain material, collect more data before optimizing or recommending a route.
Headroom — baseline.json must show failing-but-promptable rows. No
incumbent failures → nothing to optimize. A strong model fails them too →
task beyond frontier; stop.
Models — student = a cheap candidate; reflection_lm = a strong frontier
model (optional, but a weak one caps quality). Inference defaults to
Understudy within the activated workflow:
understudy login --email <developer-email>, then
understudy run -- <local command>. Fall back to the developer's own
provider keys only if they choose BYO. See reference.md → Inference.
Scope boundary — optimizing the prompt, route, or parser of a workload's
policy model is in scope, including an agentic / tool-use policy. Treat one
full agent rollout as the unit and the rubric as the metric. Only RL
trajectory/policy training and stateful verifier environments are out of
scope; that is the handoff in
../prepare-verifier-handoff/SKILL.md.
For agentic eval/optimization, set up the rollout harness and rubric in
../optimize-agentic-workload/SKILL.md
first, then return here for the GEPA prompt pass.
Stopping rule — if the scorer saturates to 1.0 fast, the surface is too
easy; strengthen the metric, don't claim. If GEPA stalls with headroom left,
recommend the next rung (SFT/distillation); this skill does not train.
Flow
- Inspect the required artifacts and confirm they describe the same workload.
- Re-state the metric, validator, split boundary, incumbent score, latency
basis, cost basis if available, and failure taxonomy.
- Select the highest-leverage intervention that matches the observed failure mode:
prompt repair, parser/schema repair, context trimming, route change,
candidate model comparison, or GEPA. When the complaint is cost (not
quality) and inputs dominate the bill, check prompt-cache structure first —
it's often the cheapest lever of all:
references/prompt-cache-optimization.md.
Prefer the lowest-cost target only among options expected to resolve the
failure; do not spend several weak iterations avoiding a stronger model or
broader experiment. See reference.md → Optimization-Target
Menu for the full list. For an agentic workload, treat latency
and cost per rollout as first-class objectives alongside the rubric score —
tool-call count, redundant calls, and wasted context are common, optimizable
failure modes, not just quality misses.
- For GEPA/DSPy execution, use a small local
uv environment when selected by
the activated workflow. Do not vendor GEPA/DSPy or depend on a full private
runtime. The CLI owns a registry-backed adapter wrapper:
optimize-workload adapter run --adapter <name> ... --execute.
eval-input-gepa runs upstream GEPA locally without provider calls unless a
model-backed path is explicitly selected. adapter run --adapter dspy-gepa --execute uses exact dspy==3.3.0, gepa[dspy]==0.1.1, and
cloudpickle==3.1.2 packages and
additionally requires separate student/reflection model names, an approved dollar cap, and explicit input
and output token prices before it resolves the Understudy API key. It passes
auth to the child process through environment only, disables client-side
retries, and reserves each request against one cumulative price-basis ledger before
running train/dev rows. A program bridge may bind student and reflection to
independent credential-free routes by naming credential environment
variables; missing mappings use the Understudy Gateway. Receipt the
requested alias, exact executed DSPy/LiteLLM model, and only response model
identity actually exposed. Do not infer ZDR from a route name or
workload_capture: false. Treat the resulting attribution
as a conservative cap under the supplied prices, not a provider invoice. GEPA's
edge is natural-language feedback: the metric must return a diagnosis of
why each failing row failed and what to change, not a bare score — bland
feedback wastes the optimizer. For an agentic workload this means the
per-criterion rubric must emit, per failing row, a short natural-language
note tied to the rollout — e.g. "called search 6 times for a fact on the
first result page; tighten the stop condition" or "answer omitted the date
filter the question required; add it to the query plan" — rather than a bare
0.
Start new GEPA runs with --num-threads 1; use pareto selection and opt into
merge only when the approved budget covers it. For a workload-owned program,
first pass --program-bridge ... --admission-only, inspect its hashed offline
and one-episode live receipt, then compile separately with the exact
--admission-receipt. Admission must fail unless provider-free validation
separately binds the typed input-row bundle and proves the exact endpoint
executable bundle was loaded, typed request/expected/tool contracts passed,
package/adapter/tool-schema hashes match, and every required write produced
an actual world-state delta. Never score a hash-only expectation or an HTTP
200 response that failed local parsing as model behavior. The bridge metric
returns ScoreWithFeedback; its optional export callback writes a canonical,
provenance-bound deployable bundle.
Keep workload package/lock pins workload-scoped; never copy one workload's
verifier/MCP bump into another workload.
- Keep deterministic work in the TypeScript CLI and this skill's templates. Follow
../../docs/optimize-workload-contract.md
for adapter, metric feedback, and claim packet details.
- When GEPA is selected in the activated plan, run train/dev-only and
record the command, model/deployment, metric-call budget, dollar cap, token
price basis, reserved upper bound, attributed usage, seed, selected
candidate, rejected variants when available, and whether provider calls were
made through Understudy.
- Freeze the candidate before any holdout validation.
- Run holdout only once the candidate is frozen, and record score, failures,
latency basis, cost basis, fallback route, demotion trigger, and caveats.
Inspect the actual rows behind material deltas before naming a win. A narrow
first pass that improves train/dev but regresses holdout is an overfitting
diagnosis, not evidence to iterate on the sealed rows; expand or rebalance a
new split contract and start a fresh experiment.
The home of record for an optimization run is the active experiment
directory (see the Experiment section of
../understudy/SKILL.md for the record shape):
.understudy/experiments/<exp-id>/ # experiment.json, candidate.json, claim.json
Open or reuse an experiment before optimizing with understudy experiments new
(it pins the current baseline); experiments/active names it. On
optimize-workload adapter run --execute the produced candidate is frozen into
the active experiment directory automatically; understudy experiments freeze
does it explicitly and also freezes a --claim-from <path>. The optimizer's
working artifacts (eval-input-candidate.json, proof-packet.json, adapter
outputs) stay under .understudy/optimize-workload/. Run understudy next to
see the current loop step.
The previous Python helper scripts have been removed with the Python CLI
prototype. Use the TypeScript CLI gates first, and still inspect artifacts
directly when a workload has unusual validator, split, or claim-boundary shape.
Block on stale hashes, missing metric feedback, unapproved provider calls, or
proxy-only validation.
Use the CLI guide before creating a local optimizer env:
understudy skills --search gepa
understudy optimize-workload adapter run --repo . --adapter eval-input-gepa --manifest eval-input-manifest.json --execute
If approved, let the named adapter create its exact ignored uv runtime:
understudy optimize-workload adapter run --repo . --adapter dspy-gepa --help
Do not preinstall a floating DSPy/GEPA environment; the adapter pins and
receipts its compatible package pair.
Claim Rules
Do not claim savings without:
.understudy/experiments/<exp-id>/claim.json
claim.json must cite harness.json, metric.json, splits.json,
baseline.json, and the frozen candidate artifact. It must include the same
harness_sha256, metric_sha256, and splits_sha256 values from the
baseline contract, plus baseline_sha256 and the frozen candidate hash. It
must also include sample size, split used, score delta, latency basis, cost
basis, price assumptions, request-volume assumption, confidence level, caveats,
fallback route, and demotion trigger. Two rigor fields are also required
(see ../../docs/benchmark-rigor.md): the
trivial-agent floor from baseline.json (null_floor — the claim is invalid
if a do-nothing agent also clears the bar), and a bootstrap confidence
interval over per-row holdout scores for both baseline and candidate — if the
intervals overlap, report an optimization lead, not a win. For an agentic workload, latency and cost
basis are per-rollout and mandatory, not optional: report the delta in tool-call
count and end-to-end rollout cost alongside the rubric delta, so a quality gain
bought with more calls or higher latency is visible rather than hidden.
Per-row eval evidence behind any claim — the baseline rerun, dev-set
comparisons, and the frozen-candidate holdout table — must be recorded as
understudy.eval_result.v1 rows
(schemas/understudy.eval_result.v1.schema.json).
The row-level provenance.harness_sha256 and provenance.split_sha256 fields
carry the same hash chain the claim packet cites, a score of 0 is a scored
failure (never a missing value), and unscored rows are excluded from
averages rather than counted as 0.
No claim may imply replacement readiness, production readiness, or recurring
savings unless those fields are present and the holdout evidence supports the
statement. If the evidence is train/dev-only, call it an optimization lead, not
a win.
Output Standard
End with:
- required artifacts inspected and freshness status;
- validation or optimization run;
- split used and whether holdout remained untouched;
- candidate status and whether
claim.json exists;
- result type: validation, optimization, heldout, or blocked;
- one recommended next local command or action.
1---2name: optimize-workload3description: Use when a developer has a measured eval and wants the prompt or route improved without retraining — "optimize my prompt against my eval", "close the quality gap with the cheaper model", "squeeze cost without losing quality". Keeps holdout sealed, runs GEPA (automatic prompt evolution) on train/dev only, and requires a claim packet before any savings statement.4---56# Optimize Workload78Use this worker only after the workload has fresh local artifacts from9`capture-evidence`. Validation and optimization must be evidence-led and10split-safe.1112## Safety Gates1314Default to the intervention with the highest expected progress toward the15objective under hard constraints, not the cheapest rung. State the expected16quality gain, time, spend envelope, and evidence before execution; follow17[`../understudy/reference.md`](../understudy/reference.md) → Outcome-first spend18posture. A developer action that launches a named bounded optimization plan19authorizes its declared model calls, uploads, hosted work, evaluation, receipts,20and cleanup. Do not pause for phase-by-phase confirmation. Ask again only if the21plan expands its displayed data, destination, spend, retention, download, or22production-impact envelope. Follow the repo public boundary in23[`../../docs/privacy-and-data-boundaries.md`](../../docs/privacy-and-data-boundaries.md)24for prompts, completions, traces, labels, datasets, repo paths, secrets, and25private notes.2627## Refusal Gate2829Refuse to optimize unless all required artifacts are present and fresh:3031```text32.understudy/capture-evidence/harness.json33.understudy/capture-evidence/metric.json34.understudy/capture-evidence/splits.json35.understudy/capture-evidence/baseline.json36```3738Fresh means generated for the same workload, metric, split contract, and39incumbent baseline in the current task context. Freshness is hash-bound:40`baseline.json` must include `harness_sha256`, `metric_sha256`, and41`splits_sha256`, and those values must match the current `harness.json`,42`metric.json`, and `splits.json`. If freshness is ambiguous or hashes do not43match, route back to44[`../capture-evidence/SKILL.md`](../capture-evidence/SKILL.md) instead45of optimizing.4647## Split Rules4849- GEPA is train/dev-only.50- Prompt, route, parser, renderer, and candidate selection changes may use51 train and dev only.52- Never mutate holdout rows, labels, validators, thresholds, or sampling after53 optimization begins.54- Holdout is only for final validation after the candidate is frozen.55- If holdout is touched accidentally, mark the result contaminated and create a56 new split contract before claiming progress.5758## Before You Optimize5960Confirm these before spending GEPA budget — full detail, model defaults, and61validator kinds in [`reference.md`](reference.md):6263- **Evidence gates** — apply the coverage, harness-conformance, qualitative64 row-review, and claim-strength gates in65 [`../capture-evidence/references/evaluation-evidence-gates.md`](../capture-evidence/references/evaluation-evidence-gates.md).66 Do not optimize a narrow easy cohort as though it represents the workload.67 Inspect the real rows behind the baseline headline and confirm important hard68 strata have train/dev and sealed-holdout representation. Treat a small pilot69 as a plumbing check only; if uncertainty, variance, or new failure classes70 remain material, collect more data before optimizing or recommending a route.7172- **Headroom** — `baseline.json` must show failing-but-promptable rows. No73 incumbent failures → nothing to optimize. A strong model fails them too →74 task beyond frontier; stop.75- **Models** — student = a cheap candidate; `reflection_lm` = a strong frontier76 model (optional, but a weak one caps quality). **Inference defaults to77 Understudy** within the activated workflow:78 `understudy login --email <developer-email>`, then79 `understudy run -- <local command>`. Fall back to the developer's own80 provider keys only if they choose BYO. See reference.md → Inference.81- **Scope boundary** — optimizing the prompt, route, or parser of a workload's82 policy model is in scope, including an *agentic / tool-use* policy. Treat one83 full agent rollout as the unit and the rubric as the metric. Only RL84 *trajectory/policy training* and stateful verifier environments are out of85 scope; that is the handoff in86 [`../prepare-verifier-handoff/SKILL.md`](../prepare-verifier-handoff/SKILL.md).87 For agentic eval/optimization, set up the rollout harness and rubric in88 [`../optimize-agentic-workload/SKILL.md`](../optimize-agentic-workload/SKILL.md)89 first, then return here for the GEPA prompt pass.90- **Stopping rule** — if the scorer saturates to 1.0 fast, the surface is too91 easy; strengthen the metric, don't claim. If GEPA stalls with headroom left,92 recommend the next rung (SFT/distillation); this skill does not train.9394## Flow95961. Inspect the required artifacts and confirm they describe the same workload.972. Re-state the metric, validator, split boundary, incumbent score, latency98 basis, cost basis if available, and failure taxonomy.993. Select the highest-leverage intervention that matches the observed failure mode:100 prompt repair, parser/schema repair, context trimming, route change,101 candidate model comparison, or GEPA. When the complaint is cost (not102 quality) and inputs dominate the bill, check prompt-cache structure first —103 it's often the cheapest lever of all:104 [`references/prompt-cache-optimization.md`](references/prompt-cache-optimization.md).105 Prefer the lowest-cost *target* only among options expected to resolve the106 failure; do not spend several weak iterations avoiding a stronger model or107 broader experiment. See [`reference.md`](reference.md) → Optimization-Target108 Menu for the full list. For an agentic workload, treat latency109 and cost per rollout as first-class objectives alongside the rubric score —110 tool-call count, redundant calls, and wasted context are common, optimizable111 failure modes, not just quality misses.1124. For GEPA/DSPy execution, use a small local `uv` environment when selected by113 the activated workflow. Do not vendor GEPA/DSPy or depend on a full private114 runtime. The CLI owns a registry-backed adapter wrapper:115 `optimize-workload adapter run --adapter <name> ... --execute`.116 `eval-input-gepa` runs upstream GEPA locally without provider calls unless a117 model-backed path is explicitly selected. `adapter run --adapter dspy-gepa118 --execute` uses exact `dspy==3.3.0`, `gepa[dspy]==0.1.1`, and119 `cloudpickle==3.1.2` packages and120 additionally requires separate student/reflection model names, an approved dollar cap, and explicit input121 and output token prices before it resolves the Understudy API key. It passes122 auth to the child process through environment only, disables client-side123 retries, and reserves each request against one cumulative price-basis ledger before124 running train/dev rows. A program bridge may bind student and reflection to125 independent credential-free routes by naming credential environment126 variables; missing mappings use the Understudy Gateway. Receipt the127 requested alias, exact executed DSPy/LiteLLM model, and only response model128 identity actually exposed. Do not infer ZDR from a route name or129 `workload_capture: false`. Treat the resulting attribution130 as a conservative cap under the supplied prices, not a provider invoice. GEPA's131 edge is natural-language feedback: the metric must return a diagnosis of132 *why* each failing row failed and what to change, not a bare score — bland133 feedback wastes the optimizer. For an agentic workload this means the134 per-criterion rubric must emit, per failing row, a short natural-language135 note tied to the rollout — e.g. "called search 6 times for a fact on the136 first result page; tighten the stop condition" or "answer omitted the date137 filter the question required; add it to the query plan" — rather than a bare138 `0`.139 Start new GEPA runs with `--num-threads 1`; use pareto selection and opt into140 merge only when the approved budget covers it. For a workload-owned program,141 first pass `--program-bridge ... --admission-only`, inspect its hashed offline142 and one-episode live receipt, then compile separately with the exact143 `--admission-receipt`. Admission must fail unless provider-free validation144 separately binds the typed input-row bundle and proves the exact endpoint145 executable bundle was loaded, typed request/expected/tool contracts passed,146 package/adapter/tool-schema hashes match, and every required write produced147 an actual world-state delta. Never score a hash-only expectation or an HTTP148 200 response that failed local parsing as model behavior. The bridge metric149 returns `ScoreWithFeedback`; its optional export callback writes a canonical,150 provenance-bound deployable bundle.151 Keep workload package/lock pins workload-scoped; never copy one workload's152 verifier/MCP bump into another workload.1535. Keep deterministic work in the TypeScript CLI and this skill's templates. Follow154 [`../../docs/optimize-workload-contract.md`](../../docs/optimize-workload-contract.md)155 for adapter, metric feedback, and claim packet details.1566. When GEPA is selected in the activated plan, run train/dev-only and157 record the command, model/deployment, metric-call budget, dollar cap, token158 price basis, reserved upper bound, attributed usage, seed, selected159 candidate, rejected variants when available, and whether provider calls were160 made through Understudy.1617. Freeze the candidate before any holdout validation.1628. Run holdout only once the candidate is frozen, and record score, failures,163 latency basis, cost basis, fallback route, demotion trigger, and caveats.164 Inspect the actual rows behind material deltas before naming a win. A narrow165 first pass that improves train/dev but regresses holdout is an overfitting166 diagnosis, not evidence to iterate on the sealed rows; expand or rebalance a167 new split contract and start a fresh experiment.168169The home of record for an optimization run is the **active experiment**170directory (see the Experiment section of171[`../understudy/SKILL.md`](../understudy/SKILL.md) for the record shape):172173```text174.understudy/experiments/<exp-id>/ # experiment.json, candidate.json, claim.json175```176177Open or reuse an experiment before optimizing with `understudy experiments new`178(it pins the current baseline); `experiments/active` names it. On179`optimize-workload adapter run --execute` the produced candidate is frozen into180the active experiment directory automatically; `understudy experiments freeze`181does it explicitly and also freezes a `--claim-from <path>`. The optimizer's182working artifacts (`eval-input-candidate.json`, `proof-packet.json`, adapter183outputs) stay under `.understudy/optimize-workload/`. Run `understudy next` to184see the current loop step.185186The previous Python helper scripts have been removed with the Python CLI187prototype. Use the TypeScript CLI gates first, and still inspect artifacts188directly when a workload has unusual validator, split, or claim-boundary shape.189Block on stale hashes, missing metric feedback, unapproved provider calls, or190proxy-only validation.191192Use the CLI guide before creating a local optimizer env:193194```bash195understudy skills --search gepa196understudy optimize-workload adapter run --repo . --adapter eval-input-gepa --manifest eval-input-manifest.json --execute197```198199If approved, let the named adapter create its exact ignored `uv` runtime:200201```bash202understudy optimize-workload adapter run --repo . --adapter dspy-gepa --help203```204205Do not preinstall a floating DSPy/GEPA environment; the adapter pins and206receipts its compatible package pair.207208## Claim Rules209210Do not claim savings without:211212```text213.understudy/experiments/<exp-id>/claim.json214```215216`claim.json` must cite `harness.json`, `metric.json`, `splits.json`,217`baseline.json`, and the frozen candidate artifact. It must include the same218`harness_sha256`, `metric_sha256`, and `splits_sha256` values from the219baseline contract, plus `baseline_sha256` and the frozen candidate hash. It220must also include sample size, split used, score delta, latency basis, cost221basis, price assumptions, request-volume assumption, confidence level, caveats,222fallback route, and demotion trigger. Two rigor fields are also required223(see [`../../docs/benchmark-rigor.md`](../../docs/benchmark-rigor.md)): the224trivial-agent floor from `baseline.json` (`null_floor` — the claim is invalid225if a do-nothing agent also clears the bar), and a bootstrap confidence226interval over per-row holdout scores for both baseline and candidate — if the227intervals overlap, report an optimization lead, not a win. For an agentic workload, latency and cost228basis are per-rollout and mandatory, not optional: report the delta in tool-call229count and end-to-end rollout cost alongside the rubric delta, so a quality gain230bought with more calls or higher latency is visible rather than hidden.231232Per-row eval evidence behind any claim — the baseline rerun, dev-set233comparisons, and the frozen-candidate holdout table — must be recorded as234`understudy.eval_result.v1` rows235([`schemas/understudy.eval_result.v1.schema.json`](../../schemas/understudy.eval_result.v1.schema.json)).236The row-level `provenance.harness_sha256` and `provenance.split_sha256` fields237carry the same hash chain the claim packet cites, a `score` of 0 is a scored238failure (never a missing value), and `unscored` rows are excluded from239averages rather than counted as 0.240241No claim may imply replacement readiness, production readiness, or recurring242savings unless those fields are present and the holdout evidence supports the243statement. If the evidence is train/dev-only, call it an optimization lead, not244a win.245246## Output Standard247248End with:249250- required artifacts inspected and freshness status;251- validation or optimization run;252- split used and whether holdout remained untouched;253- candidate status and whether `claim.json` exists;254- result type: validation, optimization, heldout, or blocked;255- one recommended next local command or action.