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).
- leverage9
- timeframe5m
- momentum0.37
- meanRev0.09
- funding0.27
- sentiment0.27
- stopLossPct4.16
- takeProfitPct1.69
- positionSizePct1.11
- riskOffDrawdownPct18.11
- leverage1
- timeframe4h
- momentum0.21
- meanRev0.47
- funding0.15
- sentiment0.17
- stopLossPct4.04
- takeProfitPct1.3
- positionSizePct1.29
- riskOffDrawdownPct22.71
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) }],
});