v3/docs/adr/ADR-351-dream-cycle-performance-stateful-execution-loop.md
Status: Proposed
Authors: claude (dream-cycle agent, 2026-06-25)
Dream Cycle Issue: #2462 (2026-06-25 nightly research)
Surfaces: performance (DEEP), security + hive-mind (SCAN)
June 2026 arXiv research (five Grade A papers) demonstrates that multi-agent orchestration frameworks leave 2–4× performance on the table by not enforcing KV-cache discipline, not scheduling tasks by dependency graph, and not applying response-level speculative routing.
Key findings:
Ruflo currently:
No competitor (LangGraph 1.2.6, AutoGen 0.7.5, CrewAI 1.14.7, OpenAI Agents SDK) has shipped any of these mechanisms.
Implement three layered optimizations in the order of implementation cost vs. impact:
Enforce a structural rule in agent construction: the system prompt and static context form a fixed prefix that is never mutated between turns. Only the dynamic message tail changes. This enables provider-side KV-cache reuse (Claude's prompt caching) without any infrastructure change.
Where: v3/@claude-flow/cli/src/agents/agent-executor.ts — add staticPrefix / dynamicSuffix split to the agent message builder.
Expose dependsOn: string[] in SwarmTaskConfig. Before dispatching a swarm, topological-sort tasks and run independent tasks concurrently. This replaces the implicit FIFO sequencing.
Where: v3/@claude-flow/cli/src/swarm/scheduler.ts (new file under 200 lines).
Add a pre-agent-call hook that routes low-complexity tool-call sequences through a draft model (Haiku), verifies with the primary model only on mismatch. Use the existing 3-tier model routing table from ADR-026.
Where: v3/@claude-flow/hooks/src/workers/speculative-router.ts (new worker).
Positive:
Negative / Risks:
Non-decisions: KV-cache pooling (PolyKV pattern) is not applicable to API-based deployments; deferred until a self-hosted inference path exists.
agent-executor.ts — 1–2 daysscheduler.ts in swarm package — 3–5 daysspeculative-router.ts worker — 3–5 days