CFN Docker Loop Orchestration Skill
Purpose: Orchestrate container-based CFN Loop execution with agent spawning, loop management, consensus collection, and product owner decision flow.
Overview
This skill manages the complete CFN Loop execution lifecycle for docker-based agents, coordinating Loop 3 (implementer) and Loop 2 (validator) phases, collecting confidence scores and consensus, and triggering Product Owner decisions.
Architecture
CFN Docker V3 Coordinator
↓ (task analysis)
CFN Docker Loop Orchestration
↓ (context storage)
Redis (State Management)
↓ (agent spawning)
CFN Docker Agent Spawning
↓ (container execution)
Docker Containers (Agents)
↓ (completion signals)
Consensus Collection
↓ (decision flow)
Product Owner Decision
Loop Execution Model
Loop 3: Primary Implementation (Implementers)
- Purpose: Create, build, and implement the solution
- Agents: 3 specialized implementers based on task requirements
- Process: Parallel execution → Confidence reporting → Gate check
Loop 2: Consensus Validation (Validators)
- Purpose: Review and validate Loop 3 work
- Agents: 2-4 validators (reviewers, testers, security specialists)
- Process: Sequential validation → Consensus collection → Decision
Loop 4: Product Owner Decision
- Purpose: Strategic decision based on consensus and deliverables
- Agent: Single product owner with GOAP methodology
- Process: Decision analysis → PROCEED/ITERATE/ABORT
Core Functions
1. Task Analysis and Context Setup
Analyze task requirements and prepare execution context:
# Initialize loop orchestration
cfn-docker-loop-orchestration init \
--task-id task-authentication \
--task-description "Implement user authentication system" \
--mode standard \
--max-iterations 5
2. Loop 3 Agent Spawning
Spawn implementer agents based on task requirements:
# Spawn Loop 3 implementers
cfn-docker-loop-orchestration spawn-loop3 \
--task-id task-authentication \
--agents backend-developer,frontend-engineer,security-specialist \
--context "${TASK_CONTEXT}"
3. Loop 3 Completion Monitoring
Monitor implementer progress and collect confidence scores:
# Monitor Loop 3 completion
cfn-docker-loop-orchestration monitor-loop3 \
--task-id task-authentication \
--wait-for-complete \
--gate-threshold 0.75
4. Gate Check and Decision
Evaluate Loop 3 results and decide next steps:
# Check Loop 3 gate
cfn-docker-loop-orchestration gate-check \
--task-id task-authentication \
--gate-threshold 0.75 \
--max-iterations 5
5. Loop 2 Validator Spawning
Spawn validator agents if gate passed:
# Spawn Loop 2 validators
cfn-docker-loop-orchestration spawn-loop2 \
--task-id task-authentication \
--agents reviewer,tester,security-specialist \
--loop3-work "${WORK_SUMMARY}"
6. Consensus Collection
Collect and analyze validator consensus:
# Collect Loop 2 consensus
cfn-docker-loop-orchestration collect-consensus \
--task-id task-authentication \
--required-consensus 0.90 \
--timeout 300
7. Product Owner Decision
Trigger final decision process:
# Trigger Product Owner decision
cfn-docker-loop-orchestration trigger-po-decision \
--task-id task-authentication \
--consensus-data "${CONSENSUS_RESULTS}"
Loop Management
Iteration Control
# Control loop iterations
cfn-docker-loop-orchestration control-iterations \
--task-id task-authentication \
--current-iteration 2 \
--max-iterations 5 \
--gate-threshold 0.75 \
--consensus-threshold 0.90
Adaptive Agent Selection
# Select agents based on iteration and feedback
cfn-docker-loop-orchestration select-adaptive-agents \
--task-id task-authentication \
--iteration 2 \
--previous-feedback "${FEEDBACK_DATA}"
Error Handling and Recovery
# Handle execution errors
cfn-docker-loop-orchestration handle-errors \
--task-id task-authentication \
--error-type agent-failure \
--failed-agent-id agent-backend-001 \
--restart-strategy adaptive
Configuration Modes
MVP Mode (Quick Execution)
cfn-docker-loop-orchestration execute \
--task-id task-authentication \
--mode mvp \
--max-iterations 3 \
--gate-threshold 0.70 \
--consensus-threshold 0.80 \
--validators 2
Standard Mode (Balanced)
cfn-docker-loop-orchestration execute \
--task-id task-authentication \
--mode standard \
--max-iterations 10 \
--gate-threshold 0.75 \
--consensus-threshold 0.90 \
--validators 3
Enterprise Mode (Thorough)
cfn-docker-loop-orchestration execute \
--task-id task-authentication \
--mode enterprise \
--max-iterations 15 \
--gate-threshold 0.85 \
--consensus-threshold 0.95 \
--validators 5
Agent Selection Strategy
Task-Based Agent Selection
# Analyze task and select appropriate agents
cfn-docker-loop-orchestration analyze-and-select \
--task-description "Implement secure user authentication" \
--output-agent-types
Skill-Based Selection
# Select agents based on required skills
cfn-docker-loop-orchestration select-by-skills \
--required-skills "security,backend-development,frontend-development" \
--agent-count 3
Experience-Based Selection
# Select agents based on previous performance
cfn-docker-loop-orchestration select-by-experience \
--task-domain authentication \
--success-threshold 0.85
Integration with CFN Docker Skills
Redis Coordination Integration
# Store loop state in Redis
cfn-docker-redis-coordination store-loop-state \
--task-id task-authentication \
--loop-number 3 \
--iteration 1 \
--state "in-progress"
# Retrieve loop state
cfn-docker-redis-coordination get-loop-state \
--task-id task-authentication \
--loop-number 3
Agent Spawning Integration
# Spawn agents with MCP configuration
cfn-docker-agent-spawn batch \
--agent-types backend-developer,frontend-engineer \
--task-id task-authentication \
--mcp-auto-select
Skill Selection Integration
# Configure MCP access for agents
for agent_type in backend-developer frontend-engineer; do
cfn-docker-skill-mcp-selector configure \
--agent-type $agent_type \
--task-id task-authentication
done
Monitoring and Observability
Loop Progress Monitoring
# Monitor overall loop progress
cfn-docker-loop-orchestration monitor-progress \
--task-id task-authentication \
--real-time \
--include-agents
# Monitor specific loop
cfn-docker-loop-orchestration monitor-loop \
--task-id task-authentication \
--loop-number 3 \
--detailed
Performance Metrics
# Collect performance metrics
cfn-docker-loop-orchestration metrics \
--task-id task-authentication \
--include-timing \
--include-resource-usage \
--include-confidence-trends
Agent Performance Tracking
# Track agent performance across loops
cfn-docker-loop-orchestration agent-performance \
--task-id task-authentication \
--agent-id agent-backend-001 \
--all-iterations
Decision Flow Logic
Gate Check Algorithm
- Collect Confidence Scores: Gather all Loop 3 confidence scores
- Calculate Average: Compute mean confidence score
- Check Threshold: Compare against gate threshold
- Decision Logic:
confidence >= threshold→ Proceed to Loop 2confidence < threshold→ Iterate Loop 3 (if iterations remaining)
Consensus Validation Algorithm
- Collect Validator Feedback: Gather all Loop 2 validator responses
- Calculate Consensus: Compute average confidence and agreement level
- Check Threshold: Compare against consensus threshold
- Decision Logic:
consensus >= threshold→ Trigger Product Ownerconsensus < threshold→ Iterate (if iterations remaining)
Product Owner Decision Triggers
- High Consensus (≥0.95): AUTO-COMPLETE
- Good Consensus (≥threshold): PROCEED to Product Owner
- Low Consensus (<threshold): ITERATE with specific feedback
Error Handling Strategies
Agent Failure Handling
# Handle agent container failure
cfn-docker-loop-orchestration handle-agent-failure \
--task-id task-authentication \
--failed-agent-id agent-backend-001 \
--strategy respawn \
--backup-agent-type backend-developer
Timeout Handling
# Handle loop timeouts
cfn-docker-loop-orchestration handle-timeout \
--task-id task-authentication \
--loop-number 3 \
--timeout-extension 300
MCP Server Failures
# Handle MCP server connectivity issues
cfn-docker-loop-orchestration handle-mcp-failure \
--task-id task-authentication \
--failed-mcp playwright \
--fallback direct-tools
Performance Optimization
Parallel Execution
- Loop 3: Spawn all implementers simultaneously
- Loop 2: Sequential validator execution to prevent conflicts
- Resource Management: Balance concurrent execution with resource limits
Adaptive Iteration
- Smart Iteration: Only iterate when specific issues identified
- Agent Specialization: Select different specialists based on feedback
- Context Preservation: Maintain context across iterations
Resource Optimization
- Container Reuse: Reuse containers where possible
- MCP Server Optimization: Share MCP servers across compatible agents
- Memory Management: Optimize memory usage across loop phases
Quality Assurance
Deliverable Validation
# Validate required deliverables created
cfn-docker-loop-orchestration validate-deliverables \
--task-id task-authentication \
--required-files "auth-service.js,login.html" \
--acceptance-criteria "${CRITERIA}"
Code Quality Checks
# Run automated quality checks
cfn-docker-loop-orchestration quality-check \
--task-id task-authentication \
--include-linting \
--include-security-scan \
--include-tests
Integration Testing
# Run integration tests for complete solution
cfn-docker-loop-orchestration integration-test \
--task-id task-authentication \
--test-suite authentication-tests
Best Practices
Loop Design
- Clear Success Criteria: Define measurable success criteria for each loop
- Appropriate Thresholds: Set realistic confidence and consensus thresholds
- Iteration Limits: Establish maximum iteration limits to prevent infinite loops
Agent Selection
- Task-Appropriate Skills: Select agents with relevant domain expertise
- Diverse Perspectives: Include different agent types for comprehensive coverage
- Performance History: Consider past agent performance when selecting
Error Recovery
- Graceful Degradation: Implement fallback mechanisms for failures
- State Persistence: Maintain state for recovery from interruptions
- Monitoring: Comprehensive monitoring for early issue detection
Configuration
Environment Variables
# Loop configuration
CFN_DOCKER_MAX_ITERATIONS=10
CFN_DOCKER_GATE_THRESHOLD=0.75
CFN_DOCKER_CONSENSUS_THRESHOLD=0.90
CFN_DOCKER_LOOP_TIMEOUT=600
# Agent configuration
CFN_DOCKER_MAX_CONCURRENT_AGENTS=5
CFN_DOCKER_AGENT_TIMEOUT=300
CFN_DOCKER_CONTAINER_MEMORY_LIMIT=1g
# Decision configuration
CFN_DOCKER_AUTO_COMPLETE_THRESHOLD=0.95
CFN_DOCKER_FORCE_ITERATION_THRESHOLD=0.60
Loop Configuration File
{
"loopConfig": {
"maxIterations": 10,
"gateThreshold": 0.75,
"consensusThreshold": 0.90,
"loopTimeouts": {
"loop3": 600,
"loop2": 300,
"productOwner": 180
}
},
"agentConfig": {
"maxConcurrentAgents": 5,
"defaultMemoryLimit": "1g",
"defaultCpuLimit": 1.0,
"restartPolicy": "on-failure"
},
"decisionConfig": {
"autoCompleteThreshold": 0.95,
"forceIterationThreshold": 0.60,
"enableAdaptiveSelection": true
}
}