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.
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 →Live example
Pulled from the current swarm: the top-PnL survivor (potential parent) and the most-recently terminated sibling (input to the mutation prompt).
- leverage5
- timeframe1h
- momentum0.13
- meanRev0.39
- funding0.36
- sentiment0.12
- stopLossPct1.26
- takeProfitPct6.91
- positionSizePct4.19
- riskOffDrawdownPct11.68
- leverage4
- timeframe1h
- momentum0.22
- meanRev0.59
- funding0.02
- sentiment0.17
- stopLossPct1.33
- takeProfitPct9.54
- positionSizePct3.03
- riskOffDrawdownPct14.08
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.
// 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) }],
});