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)
L04-A01
  • leverage5
  • timeframe1h
  • momentum0.13
  • meanRev0.39
  • funding0.36
  • sentiment0.12
  • stopLossPct1.26
  • takeProfitPct6.91
  • positionSizePct4.19
  • riskOffDrawdownPct11.68
recently terminated sibling
L18-F04
  • leverage4
  • timeframe1h
  • momentum0.22
  • meanRev0.59
  • funding0.02
  • sentiment0.17
  • stopLossPct1.33
  • takeProfitPct9.54
  • positionSizePct3.03
  • riskOffDrawdownPct14.08
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) }],
});