v3/docs/adr/ADR-366-dream-cycle-swarm-self-evolving-skill-distillation.md
Status: Proposed
Authors: claude (dream-cycle agent, 2026-07-14)
Date: 2026-07-14
Related Issues: dream-cycle nightly research 2026-07-14 (swarm slot 4)
Ruflo's swarm system produces rich execution trajectories on every run: tool-call sequences, timing, success/failure verdicts, and agent message traces are all captured by the post-task hook and stored in AgentDB. However, nothing reads these trajectories back to improve the .claude/skills/ YAML files that define coordination protocols.
Swarm Skills (arXiv:2605.10052, May 2026, Grade A) demonstrates that multi-agent coordination specs can be treated as first-class evolving assets: an automatic distillation algorithm scores each trajectory on Effectiveness × Utilization × Freshness and patches the matching skill definition. The resulting skills become progressively more efficient — without human authoring — and remain portable across agent frameworks via progressive disclosure.
The current state in Ruflo:
Implement a Swarm Skill Trajectory Distillation loop integrated into the existing post-task hook pipeline:
Trajectory capture (already exists via post-task): record tool-call sequence, agent assignments, success/failure verdicts, wall-clock latency per phase.
EUF scoring: compute Effectiveness (task success rate), Utilization (agent utilization ratio), and Freshness (recency-weighted) for each skill invocation.
Patch generation: when a skill's EUF score improves over its current definition (threshold: +5% on any dimension), generate a diff against the YAML and write it to .claude/skills/<skill-name>.yaml as a versioned patch with # distilled from trajectory <trajectory-id> comment.
Portability gate: before committing a patch, validate the updated skill still passes the existing claude-flow@v3alpha hooks verify check. Revert on failure.
Session boundary: distillation runs once at session end via session-end hook, not after every task — to avoid mid-session churn.
post-task hook → trajectory store (AgentDB)
↓
session-end hook triggers
↓
EUF scorer reads last N trajectories
↓
EUF delta > +5%?
YES → patch .claude/skills/<name>.yaml
+ hooks verify gate
NO → no-op
docs/dream-cycle/dream-gist-2026-07-14.md