v3/docs/adr/ADR-330-adaptive-pheromone-swarm-consensus.md
Status: Accepted and implemented Date: 2026-07-29 Issue: #2832 Supersedes: the research-only contract in draft PR #2833 Related: ADR-320, ADR-322, ADR-324, ADR-329
Ruflo adds the opt-in pheromone-adaptive swarm topology. It learns a bounded
fitness signal after task outcomes and controls whether an agent is eligible
for future Ruflo-managed dispatch. It does not terminate agents or expand any
agent capability.
The public initialization contract is:
ruflo swarm init \
--topology pheromone-adaptive \
--max-agents 8
The topology starts in dry-run calibration mode. Applying suspensions requires
the explicit --apsc-live flag:
ruflo swarm init \
--topology pheromone-adaptive \
--max-agents 8 \
--apsc-live
This corrects the draft proposal's --maxAgents example. Kebab-case is the
public CLI contract; camelCase remains the internal parsed/MCP representation.
Each observation is normalized before it reaches the coordinator:
raw = α × taskSuccess
+ β × (1 - normalizedLatency)
+ γ × consensusAlignment
Defaults are α=0.5, β=0.2, and γ=0.3. Inputs and weights are finite and
bounded to [0,1]; weights are normalized to sum to one.
The raw terms are observations, not interchangeable physical measurements. Ruflo therefore does not compare raw scores directly across roles. It centers each observation on the role's EMA baseline:
roleNormalized = clamp(0.5 + raw - roleBaseline, 0, 1)
agentEMA = decay × priorEMA + (1-decay) × roleNormalized
This prevents a coordinator or specialist with fewer discrete completions from being compared as though it were a task-producing coder.
The optimizer cannot trade away these invariants:
coordinator, queen, security-architect, and security-auditor are
protected by default.minSamples=3 observations before pruning.minActiveAgents=3 remain eligible.maxSuspendFraction=0.25 of active agents may be suspended in one
observation round.The implementation lives on the actual Ruflo paths:
cli/src/services/pheromone-adaptive.ts: pure scoring and safety statecli/src/mcp-tools/swarm-tools.ts: persistence and MCP operationscli/src/mcp-tools/hooks-tools.ts: automatic post-task signalcli/src/mcp-tools/agent-tools.ts: scheduling eligibility gatecli/src/commands/swarm.ts: topology and inspection CLIshared/src/core/interfaces/coordinator.interface.ts: topology contractThe earlier draft named paths that do not exist in the repository. The
implemented surface attaches to the persistent swarm store used by swarm_init
and the tracked-agent execution path used by agent_execute.
MCP operations:
swarm_pheromone_updateswarm_pheromone_statusHuman inspection:
ruflo swarm pheromone
ruflo agent metrics --format json
Manual observation:
ruflo swarm pheromone \
--agent-id coder-1 \
--role coder \
--task-success 1 \
--normalized-latency 0.2 \
--consensus-alignment 0.9
hooks_post-task emits the same observation automatically when a
pheromone-adaptive swarm is active.
The Dream-cycle report cited a 50% agent reduction and 11.6% fitness increase from a different workload. Those numbers are upstream hypotheses, not Ruflo results.
Ruflo's benchmark reports:
Release text may claim only measured Ruflo results produced by that benchmark.
hierarchical.adaptive is unchanged.apscState remain readable.agent_execute calls have no additional denial path.hooks_post-task feeds active APSC state.agent_execute refuses an agent only when live APSC marks that exact ID
suspended.agent metrics exposes the per-agent EMA pheromone score, role, sample
count, and current scheduling eligibility.