โšก Layer 4: Execution Layer

November 28, 2025 ยท View on GitHub

๐Ÿ  Home โ€บ ๐Ÿ”ง Implementation โ€บ ๐Ÿ›๏ธ Architecture โ€บ โšก Layer 4: Execution

โ† ๐Ÿ”€ Delegation Layer โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐Ÿ’พ State Layer โ†’


โšก Layer 4: Execution Layer

Where actual work happens - code execution, file operations, API calls.


Purpose

The Execution Layer performs the actual work. It contains all the tools and subagents that carry out tasks delegated by the ๐Ÿ” Main Agent.


Components

ComponentEmojiFunctionSpawned By
Subagents๐ŸฆAutonomous task executionTask tool (๐Ÿชบ spawn)
Built-in Tools๐Ÿ”งCore operations (Read, Write, Bash...)๐Ÿ” Main Agent / ๐Ÿฆ Subagents
MCP Tools๐Ÿ”ŒExternal services (Context7, Perplexity...)๐Ÿ” Main Agent / ๐Ÿฆ Subagents
User Interaction๐Ÿ’โ€โ™€๏ธHuman-in-the-loop (โ“ AskUser, ๐Ÿ“‹ Todo)๐Ÿ” Main Agent / ๐Ÿฆ Subagents

๐Ÿฆ Subagent Lifecycle

%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
stateDiagram-v2
    [*] --> Spawned: ๐Ÿชบ Task tool called
    Spawned --> Executing: Receives prompt
    Executing --> Working: Uses ๐Ÿ”ง ๐Ÿ”Œ ๐Ÿ’โ€โ™€๏ธ tools
    Working --> Working: Iterates
    Working --> Completed: โœ… Task done
    Completed --> [*]: Returns result

    note right of Working
        ๐Ÿฆ Cannot spawn
        other subagents
    end note

Tool Categories

mindmap
    root(("โšก Execution"))
        ๐Ÿ”ง Built-in Tools
            ๐Ÿ”ง๐Ÿ‘€ Read file
                Read
            ๐Ÿ”ง๐Ÿ” Search content
                Grep
            ๐Ÿ”ง๐Ÿ—‚๏ธ Search files
                Glob
            ๐Ÿ”งโœ๏ธ Write ops
                Write
                Edit
            ๐Ÿ”ง๐Ÿ“Ÿ Shell ops
                Bash
            ๐Ÿ”ง๐ŸŒ Web ops
                WebFetch
                WebSearch
        ๐Ÿ”Œ External MCP
            Context7
            Perplexity
            Firecrawl
            Custom MCPs
        ๐Ÿ’โ€โ™€๏ธ User Interaction
            โ“ AskUserQuestion
            ๐Ÿ“‹ TodoWrite
        ๐Ÿชบ Task spawn
            Spawns ๐Ÿฆ Subagents

๐Ÿ”ง Built-in Tools Reference

ToolEmojiOperation
Read๐Ÿ”ง๐Ÿ‘€Read file contents
Write๐Ÿ”งโœ๏ธCreate/overwrite files
Edit๐Ÿ”งโœ๏ธModify existing files
Glob๐Ÿ”ง๐Ÿ—‚๏ธSearch files by pattern
Grep๐Ÿ”ง๐Ÿ”Search content in files
Bash๐Ÿ”ง๐Ÿ“ŸExecute shell commands
WebFetch๐Ÿ”ง๐ŸŒFetch URL content
WebSearch๐Ÿ”ง๐ŸŒSearch the web

๐Ÿ”Œ MCP Tools (External)

ToolPurpose
Context7Up-to-date library documentation
PerplexityAI-powered web search
FirecrawlWeb scraping and crawling
Custom MCPsProject-specific integrations

๐Ÿ’โ€โ™€๏ธ User Interaction Tools

ToolEmojiPurpose
AskUserQuestionโ“Request clarification
TodoWrite๐Ÿ“‹Track task progress

๐Ÿš‚ Parallel Execution

%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TB
    classDef main fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff
    classDef subagent fill:#ec4899,stroke:#db2777,stroke-width:2px,color:#ffffff
    classDef state fill:#10b981,stroke:#059669,stroke-width:2px,color:#ffffff

    MA["๐Ÿ” Main Agent"]:::main

    MA -->|๐Ÿชบ Task| SA1["๐Ÿฆ Subagent 1"]:::subagent
    MA -->|๐Ÿชบ Task| SA2["๐Ÿฆ Subagent 2"]:::subagent
    MA -->|๐Ÿชบ Task| SA3["๐Ÿฆ Subagent 3"]:::subagent

    SA1 --> R1[Result 1]
    SA2 --> R2[Result 2]
    SA3 --> R3[Result 3]

    R1 --> MERGE["โœ… Merge Results"]:::state
    R2 --> MERGE
    R3 --> MERGE

    MERGE --> MA

Parallel Execution Rules

  1. Independence: Tasks must not depend on each other
  2. No Cross-Communication: ๐Ÿฆ Subagents cannot communicate directly
  3. Single Orchestrator: Only ๐Ÿ” Main Agent coordinates
  4. Result Aggregation: All results flow back to ๐Ÿ” Main Agent

Critical Rule

๐Ÿฆ Subagents CANNOT spawn other ๐Ÿฆ Subagents.

All delegation must flow through the ๐Ÿ” Main Agent.

โŒ Wrong Pattern

๐Ÿ” Main Agent โ†’ ๐Ÿฆ Subagent 1 โ†’ ๐Ÿฆ Subagent 2  โŒ INVALID

โœ… Correct Pattern

๐Ÿ” Main Agent โ†’ ๐Ÿฆ Subagent 1
              โ†’ ๐Ÿฆ Subagent 2
              โ†’ ๐Ÿฆ Subagent 3

Layer Position

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿ”€ LAYER 3: DELEGATION LAYER                       โ”‚
โ”‚  ๐Ÿฆด Slash Commands, ๐Ÿ“š Skills - workflow definition โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
                          โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  โšก LAYER 4: EXECUTION LAYER  โ—„โ”€โ”€โ”€ YOU ARE HERE    โ”‚
โ”‚  ๐Ÿฆ Subagents, ๐Ÿ”ง Built-in, ๐Ÿ”Œ External, ๐Ÿ’โ€โ™€๏ธ User   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                          โ”‚
                          โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ๐Ÿ’พ LAYER 5: STATE LAYER                            โ”‚
โ”‚  Memory, Files, Context - persistence               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

โ† ๐Ÿ”€ Delegation Layer โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ—โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ” ๐Ÿ’พ State Layer โ†’