协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
workflow-orchestration-patterns【开发与工程】Implements intelligent workflow orchestration patterns with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: workflow-orchestration-patterns compatibility: opencode completeness: 95 content-types:
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.
┌───────────────────────────────────────────────────────────────────────────────┐ │ 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 │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘
Use this skill when:
Avoid this skill for:
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.
Score Available Skills - Calculate match scores using multi-factor algorithm:
Checkpoint: Skip to fallback if no skill scores above threshold.
Select Optimal Skill - Choose skill with highest score that meets minimum confidence. Checkpoint: Verify skill has not been disabled or deprecated.
Execute with Fallback - Run skill execution wrapped in retry and fallback logic. Checkpoint: Log all execution attempts for audit trail.
Return or Fallback - Either return successful result or apply fallback chain:
related-skillsCheckpoint: Record outcome with timing and confidence metadata.
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", [])
}
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}")
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.
| Skill | Purpose | |