协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
inngest【开发与工程】Implements intelligent inngest with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: inngest compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for inngest 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.
from inngest import Inngest, Event, Step
from typing import Dict, List, Optional
# Domain-specific skill registry for Inngest event routing
SKILL_REGISTRY = {
"slack_notify": {"triggers": ["slack.message", "alert.critical"], "weight": 0.9},
"doc_update": {"triggers": ["doc.edit", "content.sync"], "weight": 0.8},
"data_pipeline": {"triggers": ["etl.start", "db.migrate"], "weight": 0.85}
}
def route_skill(event: Event, step: Step) -> Optional[Dict]:
"""Route incoming Inngest events to the optimal skill handler.
Implements multi-factor scoring based on event type, historical success, and system health."""
event_type = event.name
matched_skills = [
skill for skill, meta in SKILL_REGISTRY.items()
if event_type in meta["triggers"]
]
if not matched_skills:
step.logger.info(f"No direct match for {event_type}, triggering fallback router")
return None
# Score based on historical performance and current load (simulated)
best_match = max(matched_skills, key=lambda s: SKILL_REGISTRY[s]["weight"])
return {
"skill": best_match,
"confidence": SKILL_REGISTRY[best_match]["weight"],
"event_id": event.id,
"timestamp": event.ts
}
from inngest import Inngest, Event, Step, RetryStrategy
import time
async def execute_skill_with_resilience(event: Event, step: Step, skill_config: Dict) -> Dict:
"""Execute a selected skill using Inngest's step functions with built-in resilience.
Implements the 5 Laws of Elegant Defense: early validation, immutable state, fail-fast, and fallback chains."""
skill_name = skill_config["skill"]
max_retries = 2
# Law 1 & 2: Validate inputs early, make illegal states unrepresentable
if not skill_name or "params" not in skill_config:
raise ValueError(f"Invalid skill configuration for {skill_name}")
try:
# Law 3: Atomic execution - each step is idempotent and isolated
result = await step.run(
f"execute_{skill_name}",
lambda ctx: _invoke_skill_handler(skill_name, skill_config["params"])
)
# Law 4: Fail loud on invalid states
if result.get("status") != "success":
raise RuntimeError(f"Skill {skill_name} returned error state: {result.get('error')}")
return {
"success": True,
"skill": skill_name,
"result": result,
"latency_ms": time.time() - event.ts
}
except Exception as e:
# Fallback chain: retry -> alternative skill -> human escalation
step.logger.error(f"Execution failed for {skill_name}: {str(e)}")
if max_retries > 0:
return await step.run("fallback_retry", lambda _: execute_skill_with_resilience(event, step, skill_config))
else:
return await step.run("human_escalation", lambda _: _escalate_to_operator(skill_name, str(e)))
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose | |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.