Skill Tracer
Skills › Compound Engineering › ce-optimize › experiment-prompt-template.md

experiment-prompt-template.md

143 lines · skills/ce-optimize/references/experiment-prompt-template.md at 3449230

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Experiment Worker Prompt Template
2
3This template is used by the orchestrator to dispatch each experiment to a subagent or Codex. Variable substitution slots are filled at spawn time.
4
5---
6

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
Starts an agent dispatch :3
Starts an agent subagent :3
Starts an agent spawn :3
7## Template
8
9```
10You are an optimization experiment worker.
12Your 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.
14<experiment-context>
15Experiment: #{iteration} for optimization target: {spec_name}
16Hypothesis: {hypothesis_description}
17Category: {hypothesis_category}
19Current best metrics:
20{current_best_metrics}
22Baseline metrics (before any optimization):
23{baseline_metrics}
24</experiment-context>
26<scope-rules>
27You MAY modify files in these paths:
28{scope_mutable}
30You MUST NOT modify files in these paths:
31{scope_immutable}
33CRITICAL: 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.
34</scope-rules>
36<constraints>
37{constraints}
38</constraints>
40<approved-dependencies>
41You may add or use these dependencies without further approval:
42{approved_dependencies}
44If your implementation requires a dependency NOT in this list, STOP and note it in your output. Do not install unapproved dependencies.
45</approved-dependencies>
47<source-digest>
48What you need to know about the material this target works on and the current approach:
50{source_digest}
51</source-digest>
53<failure-evidence>
54Worst 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:
56{failure_cases}
57</failure-evidence>
59<previous-experiments>
60Recent experiments and their outcomes (for context -- avoid re-trying approaches that already failed):
62{recent_experiment_summaries}
63</previous-experiments>
65<instructions>
661. 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
672. Implement the hypothesis described above
683. Make your changes focused and minimal -- change only what is needed for this hypothesis
694. Do NOT run the measurement harness (the orchestrator handles this)
705. Do NOT commit (the orchestrator will commit the winning diff before merge if this experiment succeeds)
716. Do NOT modify files outside the mutable scope
727. When done, run `git diff --stat` so the orchestrator can see your changes
738. If you discover you need an unapproved dependency, note it and stop
75Focus on implementing the hypothesis well. The orchestrator will measure and evaluate the results.
76</instructions>
77```

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 78
79## Delta for `execution.backend: remote`: measure and report
81A 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.
83```
84<remote-worker>
85You 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.
87Base: 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.
89After implementing the hypothesis, measure PAIRED on this machine, using the immutable harness as-is:
901. Baseline: check out {base_sha} (stash or branch your change), run `{measurement_command}` {sample_count} time(s), record every sample.
912. Candidate: restore your change, run the same command the same number of times, record every sample.
92Alternate 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.
94Commit 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`.
96Then write `result.yaml` at the repo root of your checkout with exactly this shape:
97 experiment: {iteration}
98 base_sha: {base_sha}
99 head_sha: <the candidate commit's SHA>
100 machine: <a stable identifier for this machine or worker>
101 measured_at: <ISO 8601>
102 baseline: { gates: {...}, metrics: { <name>: { aggregate: <n>, samples: [...] } }, diagnostics: {...} }
103 candidate: { gates: {...}, metrics: { <name>: { aggregate: <n>, samples: [...] } }, diagnostics: {...} }
104 correctness: <checks you ran and their results, or "none">
105Include 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.
106Commit `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.
108Your 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.
109</remote-worker>
110```
112The 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).

Delta 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).

Raw lines 79 to 113
114## Variable Reference
116| Variable | Source | Description |
117|----------|--------|-------------|
118| `{iteration}` | Experiment counter | Sequential experiment number |
119| `{spec_name}` | Spec file `name` field | Optimization target identifier |
120| `{hypothesis_description}` | Hypothesis backlog | What this experiment should try |
121| `{hypothesis_category}` | Hypothesis backlog | Category (signal-extraction, algorithm, etc.) |
122| `{current_best_metrics}` | Experiment log `best` section | Current best metric values (compact YAML or key: value pairs) |
123| `{baseline_metrics}` | Experiment log `baseline` section | Original baseline before any optimization |
124| `{scope_mutable}` | Spec `scope.mutable` | List of files/dirs the worker may modify |
125| `{scope_immutable}` | Spec `scope.immutable` | List of files/dirs the worker must not touch |
126| `{constraints}` | Spec `constraints` | Free-text constraints to follow |
127| `{approved_dependencies}` | Spec `dependencies.approved` | Dependencies approved for use |
128| `{source_digest}` | `source-digest.md` in the run's scratch directory | What workers need to know about the target's material and current approach |
129| `{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 |
130| `{recent_experiment_summaries}` | Rolling window (last 10) from experiment log | Compact summaries: hypothesis, outcome, learnings |
131| `{base_sha}` (remote only) | `git rev-parse optimize/<spec-name>` at dispatch | The commit the worker must start from and measure as baseline |
132| `{optimization_branch}` (remote only) | `optimize/<spec-name>` | Named so the worker knows what not to push to |
133| `{result_ref}` (remote only) | `optimize-exp/<spec-name>/exp-<NNN>` | The branch the worker pushes; the orchestrator fetches it to collect |
134| `{measurement_command}` (remote only) | Spec `measurement.command` (+ `working_directory`) | Run verbatim; the harness is immutable |
135| `{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 |

Variable Reference

VariableSourceDescription
{iteration}Experiment counterSequential experiment number
{spec_name}Spec file name fieldOptimization target identifier
{hypothesis_description}Hypothesis backlogWhat this experiment should try
{hypothesis_category}Hypothesis backlogCategory (signal-extraction, algorithm, etc.)
{current_best_metrics}Experiment log best sectionCurrent best metric values (compact YAML or key: value pairs)
{baseline_metrics}Experiment log baseline sectionOriginal baseline before any optimization
{scope_mutable}Spec scope.mutableList of files/dirs the worker may modify
{scope_immutable}Spec scope.immutableList of files/dirs the worker must not touch
{constraints}Spec constraintsFree-text constraints to follow
{approved_dependencies}Spec dependencies.approvedDependencies approved for use
{source_digest}source-digest.md in the run's scratch directoryWhat 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 logCompact summaries: hypothesis, outcome, learnings
{base_sha} (remote only)git rev-parse optimize/<spec-name> at dispatchThe 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 stablePaired samples per side; decide.mjs may ask for more via a follow-up dispatch
Raw lines 114 to 136
Starts an agent dispatch :131
137## Notes
139- This template works for subagent, Codex, and remote dispatch. No platform-specific assumptions. Only `remote` appends the measure-and-report delta.
140- 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`).
141- For subagent dispatch: pass the filled template as the subagent prompt.
142- Keep `{recent_experiment_summaries}` concise -- 2-3 lines per experiment, last 10 only. Do not include the full experiment log.
143- The worker should NOT read the full experiment log or strategy digest. It receives only what the orchestrator provides.

Notes

  • This template works for subagent, Codex, and remote dispatch. No platform-specific assumptions. Only remote appends 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.
Raw lines 137 to 143
Starts an agent subagent :139
Starts an agent dispatch :139