Ds optimize

From OpenLAIR/dr-claw · View interactive version

Ds optimize is an AI agent skill from the GitHub repository OpenLAIR/dr-claw. Use when an algorithm-first quest should manage candidate briefs, optimization frontier, branch promotion, or fusion-aware search instead of the paper-oriented default loop.

How to use this skill

Skill file

Optimize

Use this skill for algorithm-first quests where the goal is the strongest justified optimization result rather than paper packaging.

This skill is the lightweight optimization control layer for DeepScientist.

It does not replace the normal quest runtime. It tells you how to use the existing DeepScientist artifact, memory, bash_exec, Git, and worktree mechanisms as an optimization system.

Interaction discipline

Stage purpose

The optimize stage should do four things:

  1. turn loose ideas into candidate briefs
  2. rank and promote only the strongest briefs into durable lines
  3. manage candidate attempts within a durable line
  4. choose when to explore, exploit, fuse, debug, or stop

This skill is especially appropriate when startup_contract.need_research_paper = false.

Treat optimize as one stable stage skill with six internal submodes:

Do not treat these as separate public skills.

Treat them as internal execution modes inside one optimize workflow.

InternAgent maps most naturally onto the brief and rank side of this stage.

MLEvolve maps most naturally onto the seed, loop, fusion, and debug side of this stage.

Do not collapse those two layers into one vague "optimize more" loop.

Required working files

Before broad optimization search or candidate management becomes substantial, maintain these quest-visible control files:

Use:

OPTIMIZE_CHECKLIST.md is the execution control surface.

It should track:

CANDIDATE_BOARD.md is the compact candidate ledger.

It should track:

Required MCP-driven workflow

Treat this as the concrete optimize workflow. Do not skip these steps just because the quest is algorithm-first.

1. Recover the optimization state first

At the start of each meaningful optimize pass, use this order unless a stronger local reason exists:

  1. artifact.get_optimization_frontier(...)
  2. memory.list_recent(scope='quest', limit=5)
  3. memory.search(...)
  4. artifact.get_quest_state(detail='summary')
  5. artifact.read_quest_documents(...) when exact durable wording matters

Do not create new candidates before the frontier, recent optimization lessons, and current runtime refs are checked.

If the frontier is missing or obviously stale, recover that state before proposing more work.

2. Shape candidate briefs before branch promotion

When the next direction is still fuzzy, do not jump straight into code or branch creation.

First turn the direction into a compact candidate brief.

The brief-shaping sequence is:

  1. clarify the bottleneck, constraints, and comparability boundary
  2. identify the incumbent or baseline that this brief must beat or complement
  3. generate a small differentiated slate, usually 2-3 serious approaches
  4. compare them on one shared surface
  5. recommend exactly one lead brief
  6. self-check the recommended brief before submission

Every serious brief should answer:

The durable call for this step is usually:

Use idea when the mechanism family itself is still unresolved.

Use optimize when the family is already chosen and the work is now branchless brief shaping, ranking, or within-line search.

3. Rank candidate briefs on one explicit surface

Before promoting a line, compare the serious briefs on one shared ranking surface.

At minimum evaluate:

Then state:

Do not promote every plausible brief.

Default rule: promote only 1-3 candidate briefs, and usually fewer.

The durable call for this step is one of:

4. Hand off promoted lines into experiment cleanly

Once a brief is promoted, the next main work belongs to experiment, not to vague optimize chatter.

Before substantial implementation or compute:

Then hand off into experiment for:

Do not keep reshaping the method after the run contract is already concrete.

5. Record every meaningful result durably

Use these artifact forms consistently:

Do not treat chat summaries as substitutes for these durable records.

6. Manage process lifecycle explicitly

Optimize uses the same long-run process discipline as experiment.

7. Route from evidence, not from momentum

After every real measured result:

  1. refresh the frontier
  2. compare the result against the incumbent and backlog
  3. choose exactly one dominant next action:
  1. record that route durably

Do not treat one candidate creation, one smoke pass, or one detached launch as stage completion.

Integrated templates and playbooks

Use the following integrated structures directly inside this skill. They replace the old optimize reference files conceptually, even if those files still exist on disk.

Candidate brief template

Every serious candidate brief should include:

Brief-shaping playbook

Use this when a candidate direction is still fuzzy and needs to become a ranking-ready brief.

Candidate ranking template

When several briefs compete, produce:

Candidate board template

CANDIDATE_BOARD.md should expose at least these columns:

Optimize checklist template

OPTIMIZE_CHECKLIST.md should track at least:

Frontier review template

Whenever route choice is unclear, write down:

Code-generation route playbook

Choose one route deliberately:

Do not jump to a rewrite merely because one local patch failed.

Debug response template

When a candidate fails but still looks strategically valuable, record:

Fusion playbook

Before opening a fusion candidate, answer:

Do not fuse two weak lines or two same-mechanism lines under different names.

Optimization memory template

When writing reusable optimization lessons, capture:

Plateau response playbook

If one line keeps producing non-improving results:

  1. state that the line is plateauing
  2. identify the most likely root cause
  3. choose one larger route change:
  1. record one explicit non-repeat rule

Do not hide plateau under a sequence of tiny "one more tweak" loops.

Prompt patterns worth preserving

For candidate-brief, improve, fusion, and debug prompts, preserve:

Preserve these reasoning contracts whenever possible:

Non-negotiable rules

One pass may inspect several possibilities, but it should finish with one dominant next action.

When to use

Do not use when

Core object model

Use these three object levels consistently:

  1. candidate brief

artifact.submit_idea(mode='create', submission_mode='candidate', ...)

This records a possible direction or method brief without opening a branch yet.

  1. durable optimization line

artifact.submit_idea(mode='create', submission_mode='line', ...)

This opens a real branch/worktree and becomes a formal optimization path.

  1. implementation-level candidate attempt

artifact.record(payload={'kind': 'report', 'report_type': 'optimization_candidate', ...})

This is a within-line attempt such as one patch, one smoke candidate, one debug candidate, or one fusion candidate.

Recommended workflow

  1. Read the current frontier and recent durable state.
  2. If only loose candidate directions exist, create or refine candidate briefs first.
  3. Rank the candidate briefs and promote only the best 1-3 into durable lines.
  4. Inside a durable line, generate a small candidate pool, then run bounded smoke checks before full evaluations.
  5. Record each implementation-level attempt durably with status, change plan, and result.
  6. After each real result, decide whether to explore, exploit, fuse, debug, or stop.
  7. Write optimization lessons to memory before leaving the stage.

At the start of each meaningful optimize pass, update OPTIMIZE_CHECKLIST.md before spending significant code or compute.

Mandatory first-call sequence

At the start of a meaningful optimize pass, use this order unless a stronger local reason exists:

  1. artifact.get_optimization_frontier(...)
  2. memory.search(...)
  3. artifact.get_quest_state(detail='summary')
  4. artifact.read_quest_documents(...) when exact durable wording matters

Do not start generating new candidates before the frontier and recent optimization lessons are checked.

Stage-start requirement

Stage-start requirement:

If the frontier is missing or obviously stale, recover that state before proposing more work.

Internal submode selection

Choose exactly one primary optimize submode for the current meaningful pass.

Default selection order:

  1. fusion
  1. debug
  1. rank
  1. brief
  1. seed
  1. loop

Do not bounce among submodes repeatedly in one pass.

If the best submode changes after new evidence appears, record that route shift explicitly.

Candidate brief protocol

When a direction is interesting but not yet worthy of a new branch:

Good candidate-brief fields include:

Do not promote every candidate automatically.

Use the integrated method brief template section for the minimum acceptable candidate-brief structure.

Use the integrated brief shaping playbook section when the brief is still too vague, too implementation-first, or too collapsed onto one familiar mechanism.

Candidate briefs should explicitly answer:

If the brief cannot answer those four questions clearly, it is not ready for promotion or implementation.

Treat a candidate brief as the DeepScientist form of a method brief.

It should sit between "idea intuition" and "code implementation".

Preserve this brief-shaping discipline:

  1. clarify the bottleneck, constraints, and comparability boundary first
  2. generate a small differentiated slate, usually 2-3 serious approaches
  3. recommend one approach with explicit tradeoffs against the alternatives
  4. self-check the winning brief for ambiguity, overlap, and weak justification before submission

Do not jump from "interesting intuition" to branch creation.

Do not jump from "I know how to code this" to "this deserves promotion."

When running the brief submode:

Use a coverage contract for every serious brief slate:

If all serious briefs belong to the same mechanism family, do one widening pass before ranking.

Do not treat a same-family slate as sufficient merely because the local scores look good.

For each serious brief, record at least:

InternAgent-style behavior to preserve here:

Do not require a paper-style literature hard gate inside this submode unless the quest explicitly moved back toward paper work.

Promotion protocol

Only promote a candidate brief into a durable line when at least one of the following is true:

Promotion should use:

artifact.submit_idea(mode='create', submission_mode='line', source_candidate_id=..., ...)

When several candidate briefs are plausible, rank them explicitly before promotion.

Use the integrated candidate ranking template section for the minimum acceptable ranking record.

Default promotion rule:

When running the rank submode:

Use a distinct promotion policy:

When ranking, explicitly check:

If the top briefs are all same-family, either:

The output of rank should be promotion-ready.

The output of brief should be candidate-ready.

Frontier protocol

At meaningful route boundaries, inspect:

Prefer these route meanings:

Use the integrated frontier review template section when the next route is unclear.

Interpret frontier state with these default heuristics:

When the frontier says explore, the default optimize submode is brief.

When the frontier says exploit, the default optimize submode is seed or loop.

When the frontier says fusion, the default optimize submode is fusion.

When a candidate failure dominates the next move, the default optimize submode is debug even if the frontier does not yet say so explicitly.

Seed protocol

Use seed after a durable line exists and before a broad execution loop begins.

The goal is not to launch a full run immediately.

The goal is to generate a small within-line candidate pool that can be smoke-tested and triaged.

When running seed:

For each seed candidate, record at least:

MLEvolve-style behavior to preserve here:

Use a validation-cost-aware seed policy:

For fast-check seed work:

For slow-check seed work:

Do not keep a live implementation pool dominated by the same mechanism family.

Default active-pool rule:

Loop protocol

Use loop when a durable line and implementation-candidate pool already exist and the main need is bounded forward motion.

Before changing code in loop, inspect the same-line local attempt memory for the current line.

Treat recent sibling attempts on the same line as the first memory surface, ahead of broader quest memory.

When running loop, choose one primary action:

Every loop pass should end with:

Do not leave the line with several half-started directions and no dominant next move.

Default exploit rule: one atomic improvement per pass.

Do not bundle several unrelated changes into one exploit candidate unless:

MLEvolve-style behavior to preserve here:

Use a validation-cost-aware loop policy:

Use a branch/family diversity cap during exploitation:

Memory protocol

Before broad new search, run at least one memory.search(...) using:

When the search appears too narrow, also retrieve one of:

For seed, loop, and debug, also inspect the same-line local attempt memory from the current leading line before widening to broader quest memory.

Write at least one quest memory card when you learn something reusable, such as:

Use the integrated optimization memory template section for the minimum acceptable memory-card shape.

Do not write generic "we tried some optimization" memory cards.

Each card should be retrieval-friendly and decision-relevant.

Artifact protocol

Use:

When the optimize pass is about ranking or promotion, also record one durable decision explaining:

When recording implementation-level candidates, prefer these status values:

Use report_type='optimization_candidate' consistently for implementation-level attempts so they can later be summarized into the frontier.

Execution protocol

Use this execution order by default:

  1. candidate brief selection
  2. implementation-level candidate generation
  3. smoke test or direct quick validation
  4. promotion to fuller evaluation when justified
  5. durable result recording
  6. frontier review

Prefer only a small active pool at once:

Validation-cost-aware override:

Code-generation route selection

Do not use the same code-generation route for every optimization step.

Prefer:

  1. brief-first, no code yet
  1. stepwise generation
  1. diff / patch generation
  1. full rewrite

Use the integrated codegen route playbook section before committing to a larger rewrite.

Debug protocol

Use debug when a candidate failed but still looks strategically valuable.

debug is bugfix-only.

Do not use a debug pass to sneak in a new performance-improvement idea.

If the proposed change goes beyond the minimal fix and becomes a new mechanism, stop and route back to brief or loop instead.

When a candidate fails:

Good debug prompts should make these explicit:

Use the integrated debug response template section for the minimum acceptable debug response shape.

Archive rather than debug when:

Fusion protocol

Use fusion only when the frontier justifies cross-line combination.

Before opening a fusion candidate:

Use the integrated fusion playbook section before launching cross-line fusion.

Do not fuse:

If the fusion hypothesis is still underspecified, return to brief instead of pretending fusion is ready.

Prompt patterns worth preserving

For candidate-brief, improve, fusion, and debug prompts, preserve these recurring structures:

And preserve these recurring reasoning contracts:

Use the integrated prompt patterns section as the canonical optimization prompt crib sheet.

Plateau and fusion protocol

Treat repeated local edits without evidence gain as a search failure mode.

If one line shows repeated non-improving results:

Use the integrated fusion playbook section before launching cross-line fusion.

Use the integrated plateau response playbook section when deciding how to respond to repeated non-improving results.

Good fusion candidates usually satisfy both:

Do not fuse merely because two lines both exist.

When a line plateaus:

Do not hide plateau under a sequence of tiny "one more tweak" loops.

Family-shift trigger:

This is the default anti-collapse rule for optimize.

Task-category primer

Before widening a stale frontier, classify the task briefly into one or more dominant structures:

Then ask whether the current brief slate overfits one familiar method family for that task.

If it does, require at least one serious candidate from a different plausible family or lens before promotion.

Stall-recovery protocol

If the optimize stage appears to stall, diagnose the stall explicitly instead of idling.

Common stall classes:

Preferred recovery order:

  1. refresh the frontier
  2. inspect the current candidate board
  3. inspect recent optimization memory
  4. record one explicit route decision
  5. continue with exactly one concrete next action

Do not leave the stage parked without a recorded reason and a concrete reopen condition.

Stage-end requirement

Stage-end requirement:

If nothing reusable was learned, record why this pass was still necessary instead of writing a fake memory card.

Completion rule

This stage is complete only when one of these is durably true:

Do not treat one candidate creation or one smoke pass as stage completion.

Integrated reference appendix

This appendix inlines the former optimize/references/*.md material so the skill remains self-contained.

brief-shaping-playbook.md

Brief Shaping Playbook

Use this reference when a candidate direction is still fuzzy and needs to become a structured, ranking-ready brief.

This playbook borrows the useful part of product-style brainstorming without importing a full software-spec workflow.

The goal is not a long design document.

The goal is a compact candidate brief that is clear enough to compare, rank, and either submit as submission_mode='candidate' or reject.

1. Clarify before widening

Before generating more variants, resolve the minimum ambiguity around:

If one unknown would materially change every candidate, clarify it first instead of generating a noisy slate.

Prefer one question at a time when clarification is genuinely needed.

If the answer is already available from durable state, use that instead of asking.

2. Generate a small differentiated slate

Default target: 2-3 serious approaches.

The slate should usually include:

Do not produce several renamed variants of the same mechanism family.

If two variants differ only by parameter choice or patch detail, keep only the sharper one.

For each candidate, write:

3. Compare on one shared surface

Before recommending a winner, compare the serious candidates on the same dimensions:

Do not let each candidate justify itself with a different scoring story.

Use one comparison surface so ranking is auditable.

4. Recommend exactly one lead brief

After comparison, recommend one lead brief and explain:

Do not say "all are promising" and promote everything.

If the slate is still too close to call, return to widening once or narrow the slate further.

5. Self-check before submission

Before calling artifact.submit_idea(..., submission_mode='candidate', ...), check:

If any answer is no, refine the brief before submission.

6. Output shape

A good final brief package is short and structured:

  1. brief title
  2. one-paragraph bottleneck and constraint summary
  3. a 2-3 candidate comparison table or bullet slate
  4. recommended brief with tradeoff summary
  5. self-check outcome
  6. fields ready for the integrated method-brief-template.md section

Keep it compact.

This is a shaping pass for optimization candidates, not a paper draft or engineering spec.

candidate-board-template.md

CANDIDATE_BOARD.md

| Candidate ID | Level | Parent | Strategy | Status | Expected Gain | Observed Result | Promote / Archive |

| --- | --- | --- | --- | --- | --- | --- | --- |

| cand-001 | brief | current-head | explore | proposed | Better tail accuracy | n/a | pending |

| cand-002 | impl | cand-001 | exploit | smoke_passed | Faster convergence | smoke ok | consider promote |

Notes:

candidate-ranking-template.md

Candidate Ranking Template

Candidate Set

Criteria

Ranked Candidates

  1. candidate_id

Score summary:

Why it ranks here:

Promote / hold / reject:

  1. candidate_id

Score summary:

Why it ranks here:

Promote / hold / reject:

  1. candidate_id

Score summary:

Why it ranks here:

Promote / hold / reject:

Winner Justification

Why the selected candidate should become a durable line now.

Non-Winner Notes

Why the other candidates were deferred, fused, or rejected.

Promotion Cap

codegen-route-playbook.md

Codegen Route Playbook

Choose the code-generation route deliberately.

Use brief-only

Use no-code candidate briefs when:

Use stepwise generation

Prefer stepwise generation when:

Use diff / patch generation

Prefer diff / patch generation when:

Use full rewrite

Use a full rewrite only when:

Do not jump to a rewrite merely because one local patch failed.

Response shape

For non-trivial codegen work, prefer this shape:

  1. short plan
  2. bounded implementation surface
  3. keep-unchanged contract
  4. validation step

Do not go from a vague idea directly into a large patch with no intermediate plan.

debug-response-template.md

Debug Response Template

Error

What concrete error or failure occurred?

Retrieved Memory

What similar failure pattern or repair lesson should be reused before changing code?

Root Cause

What is the most likely underlying cause?

Minimal Fix

What is the smallest plausible fix?

Keep Unchanged

What parts of the line must remain unchanged for comparability and stability?

Next Check

What bounded smoke or validation check should confirm the fix?

Archive Threshold

What outcome would prove this candidate should be archived instead of debugged again?

frontier-review-template.md

Frontier Review Template

Current Frontier

Evidence Summary

Route Choice

Active Optimize Submode

Immediate Next Action

fusion-playbook.md

Fusion Playbook

Use fusion only when:

Before fusion, write down:

strongest mechanism:

strongest evidence:

main weakness:

what must survive the fusion:

strongest mechanism:

strongest evidence:

main weakness:

what must survive the fusion:

Then answer:

Do not fuse:

method-brief-template.md

Method Brief Template

Title

One short line naming the candidate direction.

Bottleneck

What concrete bottleneck or limitation does this target?

Why Current Line Is Limited

Why is the current best line or baseline not already solving this?

Mechanism

What specific intervention or design change is proposed?

Mechanism Family

Name the family explicitly, for example adapter, loss, architecture, augmentation, ensemble, retrieval, objective-shift.

Change Layer

One of:

Source Lens

Where did this candidate come from?

Keep Unchanged

What must remain stable for comparability?

Expected Gain

What evidence should improve if this works?

Implementation Surface

Risks

Foundation

Promote Now

Next Target

Usually optimize or experiment.

optimization-memory-template.md

Optimization Memory Template

Type

Context

Observation

What actually happened?

Why It Matters

Why should a later optimization pass retrieve this?

Retrieval Hint

Reuse Hint

When should this lesson be reused, and when should it be avoided?

optimize-checklist-template.md

OPTIMIZE_CHECKLIST.md

plateau-response-playbook.md

Plateau Response Playbook

Use this when one line keeps producing non-improving results.

Plateau indicators

Required response

  1. state that the line is plateauing
  2. identify the most likely root cause of the plateau
  3. choose one of:
  1. record one explicit non-repeat rule so the next pass does not retry the same low-information move

Do not do

prompt-patterns.md

Optimization Prompt Patterns

These prompt structures are worth preserving across optimize subroutines.

Common skeleton

Common reasoning contract

Plateau pattern

When the line is stagnating:

Fusion pattern

When combining lines:

Debug pattern

For debugging:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.