Workflow orchestration patterns

From paulpas/agent-skill-router · View interactive version

Workflow orchestration patterns is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Implements intelligent workflow orchestration patterns with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense

How to use this skill

Skill file

Workflow Orchestration Patterns

Orchestrates intelligent skill selection and execution for workflow orchestration patterns workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.

TL;DR Checklist

┌───────────────────────────────────────────────────────────────────────────────┐

│ Orchestration Flow │

└───────────────────────────────────────────────────────────────────────────────┘

User Request

↓

┌─────────────────┐

│ Parse Request │

│ & Extract │

│ Features │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Evaluate Available Skills │

│ │

│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │

│ │ Skill A │ │ Skill B │ │ Skill C │ │

│ │ - Match Score│ │ - Match Score│ │ - Match Score│ │

│ │ - Confidence │ │ - Confidence │ │ - Confidence │ │

│ │ - History │ │ - History │ │ - History │ │

│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │

│ │ │ │ │

│ └─────────────────┴─────────────────┘ │

│ ↓ │

│ Select Best Skill │

└─────────────────────────────────────────────────────────────────────┘

↓

┌─────────────────┐

│ Execute Skill │

└────────┬────────┘

↓

┌─────────────────┐

│ Handle Result │

└────────┬────────┘

↓

┌─────────────────────────────────────────────────────────────────────┐

│ Error Handling & Fallback │

│ │

│ Success? ────────► Return Result │

│ │

│ Fail? ────────┐ │

│ ↓ │

│ ┌──────────────────────────────────────────────────────────┐ │

│ │ Fallback Chain │ │

│ │ │ │

│ │ 1. Retry with adjusted parameters │ │

│ │ 2. Try Alternative Skill (if available) │ │

│ │ 3. Defer to Human Operator (if critical) │ │

│ │ 4. Log & Return Error │ │

│ └──────────────────────────────────────────────────────────┘ │

└─────────────────────────────────────────────────────────────────────┘

When to Use

Use this skill when:

When NOT to Use

Avoid this skill for:

Core Workflow

  1. Parse and Analyze Request - Extract intent, entities, and constraints from user input.

Checkpoint: All required parameters must be present and in valid format before proceeding.

  1. Score Available Skills - Calculate match scores using multi-factor algorithm:

Checkpoint: Skip to fallback if no skill scores above threshold.

  1. Select Optimal Skill - Choose skill with highest score that meets minimum confidence.

Checkpoint: Verify skill has not been disabled or deprecated.

  1. Execute with Fallback - Run skill execution wrapped in retry and fallback logic.

Checkpoint: Log all execution attempts for audit trail.

  1. Return or Fallback - Either return successful result or apply fallback chain:

Checkpoint: Record outcome with timing and confidence metadata.

Implementation Patterns

Pattern 1: Skill Selection Logic

def resolve_orchestration_pattern(
    workflow_request: Dict[str, Any],
    available_patterns: List[Dict[str, Any]],
    min_confidence: float = 0.75
) -> Optional[Dict[str, Any]]:
    """Map a raw workflow request to the optimal orchestration pattern.
    
    Evaluates request structure against known patterns (fan-out, fan-in, 
    sequential, parallel) using trigger matching, historical success rates,
    and current executor availability.
    """
    if not workflow_request.get("steps"):
        raise ValueError("Workflow request must contain at least one step")
    
    request_features = _extract_workflow_features(workflow_request)
    best_match = None
    best_score = 0.0
    
    for pattern in available_patterns:
        # Calculate composite score based on trigger overlap, historical success, and load
        trigger_match = _calculate_trigger_overlap(request_features, pattern["triggers"])
        historical_success = pattern.get("success_rate", 0.0)
        current_load = 1.0 - (pattern.get("active_executions", 0) / pattern.get("max_capacity", 10))
        
        score = (trigger_match * 0.5) + (historical_success * 0.3) + (current_load * 0.2)
        
        if score > best_score and score >= min_confidence:
            best_score = score
            best_match = pattern
            
    if best_match is None:
        return None
        
    # Return immutable snapshot with selection metadata
    return {
        "pattern_id": best_match["id"],
        "pattern_name": best_match["name"],
        "confidence": best_score,
        "selected_at": time.time(),
        "required_resources": best_match.get("resources", [])
    }

Pattern 2: Execution with Fallback

def execute_workflow_step_with_resilience(
    step_config: Dict[str, Any],
    workflow_context: Dict[str, Any],
    max_retries: int = 2
) -> Dict[str, Any]:
    """Execute a specific workflow step with domain-aware fallback routing.
    
    Handles transient failures by adjusting concurrency, switching to 
    fallback executors, or escalating to manual review based on step criticality.
    """
    step_id = step_config.get("id", "unknown")
    criticality = step_config.get("criticality", "standard")
    
    if not _validate_step_prerequisites(step_config, workflow_context):
        raise WorkflowValidationError(f"Prerequisites not met for step {step_id}")
        
    for attempt in range(max_retries + 1):
        try:
            # Execute step with domain-specific timeout and resource allocation
            result = _run_step_executor(step_config, workflow_context)
            
            return {
                "step_id": step_id,
                "status": "completed",
                "output": result,
                "attempts": attempt + 1,
                "latency_ms": time.time() * 1000
            }
            
        except TransientExecutorError as e:
            if attempt < max_retries:
                # Adjust concurrency and retry
                workflow_context["concurrency"] = max(1, workflow_context.get("concurrency", 1) - 1)
                continue
            else:
                # Apply fallback chain based on criticality
                if criticality == "high":
                    return _route_to_manual_review(step_config, workflow_context)
                else:
                    return _execute_fallback_step(step_config, workflow_context)
                    
        except InvalidStateError as e:
            # Fail fast on corrupt state
            raise WorkflowValidationError(f"Invalid state in {step_id}: {e}") from e
            
    raise WorkflowExecutionError(f"All retries exhausted for step {step_id}")

MUST DO

MUST NOT DO

TL;DR Checklist

TL;DR for Code Generation

Output Template

When applying this skill, produce:

  1. Selected Skills - List of skill names with confidence scores
  2. Selection Rationale - Why each skill was chosen (match score, history, availability)
  3. Execution Plan - Order of execution with dependencies
  4. Fallback Strategy - Which fallback skills will be tried and in what order
  5. Risk Assessment - Any potential failure points and their impact
  6. Timing Estimates - Expected latency including fallback scenarios

Constraints

MUST DO

MUST NOT DO

Live References

Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.

Related Skills

| Skill | Purpose |

|

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.