dna lab

Mutation engine

How Claude Opus 4.7 turns a survivor’s DNA into a new child. Inputs: parent DNA + recently terminated siblings. Output: a mutated DNA + a rationale.

prompt summary

You are the mutation engine of a Darwinian trading swarm. Given the parent DNA and a lineage of recently terminated siblings, propose a mutated DNA that diverges from failed patterns while preserving traits correlated with survivors. Mutate 2–4 traits meaningfully; carry the rest forward. Return strict JSON with the mutated DNA and a ≤160-char rationale.

full mutation spec →
leverage
int 1..10
timeframe
1m / 5m / 1h / 4h
momentum + meanRev + funding + sentiment
sum ≈ 1.0 ± 0.05
stopLossPct
0.5..5
takeProfitPct
0.5..10
positionSizePct
1..25
riskOffDrawdownPct
5..30
rationale
string · ≤ 160 chars

Live example

Pulled from the current swarm: the top-PnL survivor (potential parent) and the most-recently terminated sibling (input to the mutation prompt).

survivor (parent)
L21-H08 →
  • leverage9
  • timeframe5m
  • momentum0.37
  • meanRev0.09
  • funding0.27
  • sentiment0.27
  • stopLossPct4.16
  • takeProfitPct1.69
  • positionSizePct1.11
  • riskOffDrawdownPct18.11
recently terminated sibling
L18-F04 →
  • leverage1
  • timeframe4h
  • momentum0.21
  • meanRev0.47
  • funding0.15
  • sentiment0.17
  • stopLossPct4.04
  • takeProfitPct1.3
  • positionSizePct1.29
  • riskOffDrawdownPct22.71
cause of death
max leverage liquidation cascade

Local fallback

When ANTHROPIC_API_KEY isn’t set, the engine falls back to a deterministic local heuristic: jitter the four signal weights, nudge leverage away from the dead-sibling average, swap timeframe one step up/down. This keeps the swarm tick runnable without paying for tokens.

code path
// src/swarm/parent.ts
const { dna, rationale } = await mutate(parentAgent.dna, deadReports);
const wallet = await createChildWallet(id);
addAgent({ id, parentId, capitalUsdc: 500, dna, ... });

// src/swarm/mutation.ts
client.messages.create({
  model: "claude-opus-4-7",
  system: MUTATION_SYSTEM_PROMPT,
  messages: [{ role: "user", content: buildPrompt(parent, dead) }],
});