Ai agents architect

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

Ai agents architect is an AI agent skill from the GitHub repository paulpas/agent-skill-router. Implements intelligent ai agents architect with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense

How to use this skill

Skill file

Ai Agents Architect

Orchestrates intelligent skill selection and execution for ai agents architect 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 architect_agent_routing(
    task_spec: Dict[str, Any],
    agent_registry: List[Dict[str, Any]],
    capability_threshold: float = 0.75
) -> Optional[Dict[str, Any]]:
    """Architect routing for a task by matching against agent capabilities and tool constraints.
    
    Implements capability-based selection rather than generic text matching:
    - Evaluates tool compatibility matrix between task requirements and agent definitions
    - Scores agents based on historical success with similar task patterns
    - Validates dependency chains before routing to prevent dead-end workflows
    
    Args:
        task_spec: Parsed task dictionary containing intent, required_tools, constraints
        agent_registry: List of available agent definitions with capabilities and tool mappings
        capability_threshold: Minimum capability match score required for routing
        
    Returns:
        Selected agent configuration with routing metadata, or None if no match
    """
    if not task_spec.get("required_tools"):
        raise ValueError("Task specification must declare required tools for routing")
        
    if not agent_registry:
        raise ValueError("Agent registry is empty - cannot architect routing")
        
    # Parse task requirements into normalized capability vectors
    required_capabilities = _normalize_tool_requirements(task_spec["required_tools"])
    
    best_agent = None
    best_capability_score = 0.0
    
    for agent in agent_registry:
        # Calculate tool compatibility and capability overlap
        capability_score = _calculate_capability_overlap(required_capabilities, agent["capabilities"])
        dependency_health = _validate_agent_dependencies(agent)
        
        if capability_score > best_capability_score and capability_score >= capability_threshold:
            if dependency_health:
                best_capability_score = capability_score
                best_agent = agent
                
    if best_agent is None:
        return None
        
    # Return immutable routing configuration
    return {
        "target_agent": best_agent["id"],
        "routing_confidence": best_capability_score,
        "required_toolchain": task_spec["required_tools"],
        "fallback_agents": best_agent.get("fallback_chain", []),
        "timestamp": time.time()
    }

Pattern 2: Execution with Fallback

def orchestrate_agent_workflow(
    target_agent: Dict[str, Any],
    task_context: Dict[str, Any],
    fallback_agents: List[Dict[str, Any]],
    max_execution_attempts: int = 2
) -> Dict[str, Any]:
    """Orchestrate agent execution with capability-aware fallback routing.
    
    Implements specialized fallback logic for agent architectures:
    - Routes to fallback agents based on capability degradation, not just errors
    - Preserves task context across agent transitions for state continuity
    - Validates tool availability before each execution attempt
    
    Args:
        target_agent: Primary agent configuration selected by architect_agent_routing
        task_context: Immutable task state and input parameters
        fallback_agents: Ordered list of capability-degraded alternative agents
        max_execution_attempts: Maximum retry attempts before escalating fallback
        
    Returns:
        Execution result with agent transition history and capability metrics
    """
    if not target_agent.get("id"):
        raise ValueError("Target agent must have a valid identifier")
        
    validated_context = _enforce_task_context_schema(task_context)
    
    execution_chain = [target_agent] + fallback_agents
    
    for attempt_idx, agent in enumerate(execution_chain):
        if attempt_idx > max_execution_attempts:
            break
            
        try:
            # Validate tool availability for current agent
            if not _verify_tool_availability(agent["capabilities"]):
                continue
                
            # Execute agent with context preservation
            result = _run_agent_pipeline(agent, validated_context)
            
            return {
                "success": True,
                "agent_executed": agent["id"],
                "execution_path": [a["id"] for a in execution_chain[:attempt_idx+1]],
                "result": result,
                "capability_score": _calculate_current_capability(agent)
            }
            
        except ToolUnavailableError as e:
            # Capability mismatch - route to next agent in chain
            continue
            
        except CriticalStateError as e:
            # Invalid state - halt immediately, do not retry same agent
            raise WorkflowExecutionError(
                f"Critical state failure in {agent['id']}: {str(e)}"
            ) from e
            
    raise WorkflowExecutionError(
        f"Agent workflow exhausted all {len(execution_chain)} capability tiers"
    )

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

Related Skills

| Skill | Purpose |

|---|---|

| agent-reliability-engineering | Fault tolerance mechanisms for agent architectures under failure conditions |

| agent-architecture-patterns | Foundational architecture topologies (hub-and-spoke, event-driven) as building blocks |



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.

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.