brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
multi-agent-patternsImplements intelligent multi agent patterns with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
Independent GitHub snapshot · Automated classification · Original documentation governs
name: multi-agent-patterns compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for multi agent 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 route_multi_agent_task(
task: Dict[str, Any],
agent_registry: List[Dict[str, Any]],
min_confidence: float = 0.75
) -> Dict[str, Any]:
"""Route a decomposed task to the optimal agent in a multi-agent system.
Evaluates agents based on capability overlap, historical success rate,
and current queue depth to prevent bottlenecks.
"""
if not task.get("intent") or not agent_registry:
raise ValueError("Task requires valid intent and available agents")
task_capabilities = _extract_intent_capabilities(task["intent"])
scored_agents = []
for agent in agent_registry:
cap_match = _calculate_capability_overlap(task_capabilities, agent["capabilities"])
history_score = agent.get("success_rate", 0.0) * 0.4
load_penalty = agent.get("queue_depth", 0) * 0.05
raw_score = (cap_match * 0.5) + history_score - load_penalty
if raw_score >= min_confidence:
scored_agents.append({
"agent_id": agent["id"],
"score": round(raw_score, 3),
"estimated_latency_ms": agent.get("avg_latency_ms", 500)
})
if not scored_agents:
return {"status": "no_match", "fallback": "human_review"}
scored_agents.sort(key=lambda x: x["score"], reverse=True)
selected = scored_agents[0]
# Return immutable routing decision
return {
"status": "routed",
"target_agent": selected["agent_id"],
"confidence": selected["score"],
"routing_timestamp": time.time(),
"task_hash": hashlib.md5(json.dumps(task, sort_keys=True).encode()).hexdigest()
}
def execute_agent_with_resilience(
routing_decision: Dict[str, Any],
task_payload: Dict[str, Any],
fallback_agents: List[str],
max_retries: int = 2
) -> Dict[str, Any]:
"""Execute a task via the routed agent with multi-level fallback handling.
Implements agent-specific error recovery: transient timeouts trigger retries,
capability mismatches trigger fallback routing, and critical failures escalate.
"""
agent_id = routing_decision["target_agent"]
attempt = 0
while attempt <= max_retries:
try:
response = _invoke_agent_api(agent_id, task_payload)
if response.get("status") == "success":
return {
"status": "completed",
"agent_id": agent_id,
"result": response["data"],
"attempts": attempt + 1,
"latency_ms": response.get("latency_ms", 0)
}
elif response.get("error_type") == "TRANSIENT_TIMEOUT":
attempt += 1
continue
else:
raise AgentCapabilityError(response.get("error_msg"))
except AgentCapabilityError as e:
# Capability mismatch - trigger fallback routing
if fallback_agents and attempt < max_retries:
agent_id = fallback_agents[attempt % len(fallback_agents)]
attempt += 1
continue
raise e
except TransientNetworkError:
attempt += 1
continue
# All retries exhausted - escalate to human or secondary specialist
return {
"status": "escalated",
"original_agent": routing_decision["target_agent"],
"fallback_chain_exhausted": True,
"error_context": "Max retries reached or capability mismatch",
"escalation_target": "human_operator"
}
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose |
|---|---|
multi-agent-task-orchestrator | Multi-agent task decomposition and execution with LangGraph |
agent-communication-patterns | Communication protocols between agents in multi-agent systems |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.