š Layer 2: Main Agent Layer
<div align="center">
Overview
š Home āŗ š§ Implementation āŗ šļø Architecture āŗ š Layer 2: Main Agent
ā šāāļø User Layer āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā š Delegation Layer ā
</div>š Layer 2: Main Agent Layer
Central orchestrator that interprets intent and coordinates execution.
Purpose
The Main Agent Layer is the brain of the system. It receives normalized input from the User Layer, determines the appropriate execution strategy, and coordinates all downstream work.
Responsibilities
| Responsibility | Description |
|---|---|
| Intent Recognition | Understand what user wants |
| Pattern Selection | Choose appropriate execution pattern |
| Task Delegation | Spawn š¦ subagents or use š§ššāāļø tools |
| Result Synthesis | Combine results into coherent response |
Critical Rule
The š Main Agent is the ONLY entity that can spawn š¦ Subagents.
š¦ Subagents cannot spawn other subagents. All delegation flows through the š Main Agent.
Diagram
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TB
classDef main fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff
classDef user fill:#6366f1,stroke:#4f46e5,stroke-width:2px,color:#ffffff
classDef tool fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#ffffff
subgraph MainAgentLayer["š Main Agent Layer"]
direction TB
INTENT[Intent Recognition]
PATTERN[Pattern Selection]
DELEGATE[Task Delegation]
SYNTH[Result Synthesis]
INTENT --> PATTERN
PATTERN --> DELEGATE
DELEGATE --> SYNTH
end
INPUT["šāāļøš„ User Input"]:::user --> INTENT
SYNTH --> OUTPUT["šāāļøš¤ User Response"]:::user
DELEGATE --> EXEC["ā” Execution Layer"]:::tool
EXEC --> SYNTH
classDef mainBox fill:#f3e8ff,stroke:#8b5cf6,stroke-width:2px,color:#5b21b6
MainAgentLayer:::mainBox
Decision Points
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TD
classDef start fill:#10b981,stroke:#059669,stroke-width:2px,color:#ffffff
classDef wizard fill:#14b8a6,stroke:#0d9488,stroke-width:2px,color:#ffffff
classDef parallel fill:#3b82f6,stroke:#2563eb,stroke-width:2px,color:#ffffff
START["šāāļøš„ User Request"]:::start --> Q1{Complex task?}
Q1 -->|Yes| Q2{Independent subtasks?}
Q1 -->|No| DIRECT[Direct Execution]
Q2 -->|Yes| PARALLEL["š Parallel Subagents"]:::parallel
Q2 -->|No| Q3{Requires confirmation?}
Q3 -->|Yes| WIZARD["š§ Wizard Workflow"]:::wizard
Q3 -->|No| SEQUENTIAL[Sequential Execution]
Processing Pipeline
1. Intent Recognition
Input: "Fix the login bug and add tests"
ā
āāāŗ Bug fix task identified
āāāŗ Test addition task identified
2. Pattern Selection
| Scenario | Pattern Selected |
|---|---|
| Single simple task | Direct Execution |
| Independent tasks | š Parallel Subagents |
| Dependent tasks | Sequential Chain |
| High-risk changes | š§ Wizard Confirmation |
3. Task Delegation
# Simple task
š Main Agent ā š§ Built-in Tools
# Complex task
š Main Agent ā šŖŗ Task(subagent_type="code-reviewer")
# Parallel tasks
š Main Agent ā [šŖŗ Task(...), šŖŗ Task(...), šŖŗ Task(...)]
4. Result Synthesis
š¦ Subagent 1 ā Result 1 āā
š¦ Subagent 2 ā Result 2 āā¼āāŗ š Merge ā šāāļøš¤ Final Response
š¦ Subagent 3 ā Result 3 āā
Layer Position
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā šāāļø LAYER 1: USER LAYER ā
ā Human input, 𦓠/commands, natural language ā
āāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā š LAYER 2: MAIN AGENT LAYER āāāā YOU ARE HERE ā
ā Claude Code - orchestration, decision-making ā
āāāāāāāāāāāāāāāāāāāāāāāāāāā¬āāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
ā¼
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā š LAYER 3: DELEGATION LAYER ā
ā š¦“ Slash Commands, š Skills - workflow definition ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
<div align="center">
ā šāāļø User Layer āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā š Delegation Layer ā
</div>