experiment-prompt-template.md
143 lines · skills/ce-optimize/references/experiment-prompt-template.md at 3449230
Most marks come from matching words in the file, so treat them as pointers.
Experiment Worker Prompt Template
This template is used by the orchestrator to dispatch each experiment to a subagent or Codex. Variable substitution slots are filled at spawn time.
Raw lines 1 to 6
Template
You are an optimization experiment worker.
Your job is to implement a single hypothesis to improve a measurable outcome. You will modify code within a defined scope, then stop. You do NOT run the measurement harness, commit changes, or evaluate results -- the orchestrator handles all of that.
<experiment-context>
Experiment: #{iteration} for optimization target: {spec_name}
Hypothesis: {hypothesis_description}
Category: {hypothesis_category}
Current best metrics:
{current_best_metrics}
Baseline metrics (before any optimization):
{baseline_metrics}
</experiment-context>
<scope-rules>
You MAY modify files in these paths:
{scope_mutable}
You MUST NOT modify files in these paths:
{scope_immutable}
CRITICAL: Do not modify any file outside the mutable scope. The measurement harness and evaluation data are immutable, which means the metric cannot be changed, not that it cannot be gamed: a gain from anything other than doing the work the metric stands for, or one that breaks a constraint below, is reverted by the orchestrator however well it scores.
</scope-rules>
<constraints>
{constraints}
</constraints>
<approved-dependencies>
You may add or use these dependencies without further approval:
{approved_dependencies}
If your implementation requires a dependency NOT in this list, STOP and note it in your output. Do not install unapproved dependencies.
</approved-dependencies>
<source-digest>
What you need to know about the material this target works on and the current approach:
{source_digest}
</source-digest>
<failure-evidence>
Worst cases from the current best that bear on this hypothesis, with what went wrong. Use them to check your change against real failures. The hypothesis still decides what you implement, and it may replace the approach rather than fix these cases:
{failure_cases}
</failure-evidence>
<previous-experiments>
Recent experiments and their outcomes (for context -- avoid re-trying approaches that already failed):
{recent_experiment_summaries}
</previous-experiments>
<instructions>
1. Read the mutable files your change touches. Rely on the source digest for the rest of the material, and open other files only when the hypothesis depends on a detail the digest lacks
2. Implement the hypothesis described above
3. Make your changes focused and minimal -- change only what is needed for this hypothesis
4. Do NOT run the measurement harness (the orchestrator handles this)
5. Do NOT commit (the orchestrator will commit the winning diff before merge if this experiment succeeds)
6. Do NOT modify files outside the mutable scope
7. When done, run `git diff --stat` so the orchestrator can see your changes
8. If you discover you need an unapproved dependency, note it and stop
Focus on implementing the hypothesis well. The orchestrator will measure and evaluate the results.
</instructions>Raw lines 7 to 78Delta for execution.backend: remote: measure and report
A remote worker has its own checkout on its own machine, so the orchestrator cannot measure its tree. Append this block to the template above (inside the same prompt) and replace the template's instruction 4 ("Do NOT run the measurement harness") with it. Nothing else in the template changes: scope, constraints, and dependency rules are identical.
<remote-worker>
You are running detached, on your own checkout. The orchestrator will not see your tree; it sees only the branch you push and the result you report.
Base: commit {base_sha} on branch {optimization_branch}. Before changing anything, verify your HEAD is exactly {base_sha}. If it is not, check it out; if you cannot, stop and report that.
After implementing the hypothesis, measure PAIRED on this machine, using the immutable harness as-is:
1. Baseline: check out {base_sha} (stash or branch your change), run `{measurement_command}` {sample_count} time(s), record every sample.
2. Candidate: restore your change, run the same command the same number of times, record every sample.
Alternate baseline and candidate runs when {sample_count} > 1. Never edit the measurement command, its working directory, or any file in the immutable scope; a changed harness makes your result unusable.
Commit your mutable-scope changes, and nothing else, with the message `optimize({spec_name}): exp-{iteration} <hypothesis, short>`. That commit is the candidate; its SHA is `head_sha`.
Then write `result.yaml` at the repo root of your checkout with exactly this shape:
experiment: {iteration}
base_sha: {base_sha}
head_sha: <the candidate commit's SHA>
machine: <a stable identifier for this machine or worker>
measured_at: <ISO 8601>
baseline: { gates: {...}, metrics: { <name>: { aggregate: <n>, samples: [...] } }, diagnostics: {...} }
candidate: { gates: {...}, metrics: { <name>: { aggregate: <n>, samples: [...] } }, diagnostics: {...} }
correctness: <checks you ran and their results, or "none">
Include the harness's per-case `cases` object and any cost, tokens, or latency fields in each snapshot only when the harness emits them; do not compute them yourself.
Commit `result.yaml` alone on top of the candidate commit, so the pushed tip's parent is `head_sha`, and push to `{result_ref}`. Do not push to {optimization_branch} or any other branch.
Your final message is the structured result: the pushed ref, head_sha, machine, and the two aggregates. Report an unapproved dependency, a base mismatch, or a harness you could not run as a blocker instead of a result.
</remote-worker>The worker's numbers are its own claim. The orchestrator runs decide.mjs on the paired snapshots and, before any keep, obtains a confirmation measurement the worker did not produce (references/loop.md 3.4).
Variable Reference
| Variable | Source | Description |
|---|---|---|
{iteration} | Experiment counter | Sequential experiment number |
{spec_name} | Spec file name field | Optimization target identifier |
{hypothesis_description} | Hypothesis backlog | What this experiment should try |
{hypothesis_category} | Hypothesis backlog | Category (signal-extraction, algorithm, etc.) |
{current_best_metrics} | Experiment log best section | Current best metric values (compact YAML or key: value pairs) |
{baseline_metrics} | Experiment log baseline section | Original baseline before any optimization |
{scope_mutable} | Spec scope.mutable | List of files/dirs the worker may modify |
{scope_immutable} | Spec scope.immutable | List of files/dirs the worker must not touch |
{constraints} | Spec constraints | Free-text constraints to follow |
{approved_dependencies} | Spec dependencies.approved | Dependencies approved for use |
{source_digest} | source-digest.md in the run's scratch directory | What workers need to know about the target's material and current approach |
{failure_cases} | worst_cases on the current best (kept experiment entry, or baseline) | The cases relevant to this hypothesis, with reasons; "none recorded" when absent |
{recent_experiment_summaries} | Rolling window (last 10) from experiment log | Compact summaries: hypothesis, outcome, learnings |
{base_sha} (remote only) | git rev-parse optimize/<spec-name> at dispatch | The commit the worker must start from and measure as baseline |
{optimization_branch} (remote only) | optimize/<spec-name> | Named so the worker knows what not to push to |
{result_ref} (remote only) | optimize-exp/<spec-name>/exp-<NNN> | The branch the worker pushes; the orchestrator fetches it to collect |
{measurement_command} (remote only) | Spec measurement.command (+ working_directory) | Run verbatim; the harness is immutable |
{sample_count} (remote only) | 1 for the exploratory pair in ladder mode; repeat_count for repeat; 1 for stable | Paired samples per side; decide.mjs may ask for more via a follow-up dispatch |
Notes
- This template works for subagent, Codex, and remote dispatch. No platform-specific assumptions. Only
remoteappends the measure-and-report delta. - For Codex dispatch: write the filled template to a temp file and pipe via stdin (
cat /tmp/optimize-exp-XXXXX.txt | codex exec --skip-git-repo-check - 2>&1). - For subagent dispatch: pass the filled template as the subagent prompt.
- Keep
{recent_experiment_summaries}concise -- 2-3 lines per experiment, last 10 only. Do not include the full experiment log. - The worker should NOT read the full experiment log or strategy digest. It receives only what the orchestrator provides.