$ cat ~/writing/2026-04-26-ai-agent-architecture-levels.md

Agent 架構的五個層級:從 L1 RAG 到 L5 Harness

DATE2026·04·26
TAGSAI · Agents · Architecture
READING5 min

「有 LLM 就是 agent」是常見的誤解。實際上 agentic system 可以依自主性、工具使用、動態規劃分成五層,從最簡單的單次呼叫,到生產級的控制平面。這篇主要照 Anthropic 的 Building Effective Agents(Dec 2024),再對一下 OpenAI 和幾篇 arXiv 研究,整理成這五層加一張選型決策樹。

5 級 Agent 架構金字塔

Level核心特徵代表
L1 Augmented LLM單次呼叫 + 工具/RAGChatGPT 網頁版 / RAG QA
L2 Workflows預定義路徑 orchestrationPrompt Chaining / Routing
L3 Autonomous Agents動態規劃 + 環境回饋Claude Code / SWE-bench
L4 Multi-Agent角色分工 + Agent 通訊AutoGen / LangGraph Multi-Agent
L5 Agent Harness控制平面 + 驗證 + 審計OpenAI Codex Harness / Azure SRE

決策原則(Anthropic):「用最簡單能解決問題的最低 level」。 L3 以上引入動態規劃 → 系統變得不可預測 → debug、成本、安全代價都跟著升,不要為了 buzzword 升級。

L2 vs L3 的分界線:有沒有 LLM 動態決定下一步。

Level 1: Augmented LLM(增強型語言模型)

Anthropic 定義:“The basic building block of agentic systems is an LLM enhanced with augmentations such as retrieval, tools, and memory”

特徵

特徵說明
核心能力單次 LLM 呼叫 + 檢索/工具/記憶
無自主規劃、無多步執行
適用簡單問答、資訊檢索

程式碼範例

# Level 1: 單次呼叫
response = llm.chat(
    messages=[{"role": "user", "content": question}],
    tools=[search_tool]
)

例子

  • ChatGPT 網頁版問問題
  • RAG 問答系統
  • 單一工具調用

Level 2: Workflows(工作流)

Anthropic 定義:“Workflows are systems where LLMs and tools are orchestrated through predefined code paths”

五種標準模式(Anthropic + LangChain 共識)

模式圖示適用場景
Prompt ChainingA → B → C任務可分解為固定子任務
RoutingInput → Classifier → Specialist不同類型需要不同處理
ParallelizationA → [B₁, B₂, B₃] → Aggregate需要多視角或速度
Orchestrator-WorkersOrchestrator → [Dynamic Workers] → Synthesize複雜任務,子任務不可預測
Evaluator-OptimizerGenerator ↔ Evaluator (loop)有明確評估標準的迭代任務

程式碼範例

# Level 2: Workflow(預定義路徑)
def workflow(input):
    step1 = llm_call(prompt_a, input)
    if check(step1):  # 門禁
        step2 = llm_call(prompt_b, step1)
    return step2

例子

  • 行銷文案生成 → 翻譯
  • 大綱檢查 → 文件撰寫
  • 客服路由(一般問題/退款/技術支援)

Level 3: Autonomous Agents(自主智能體)

Anthropic 定義:“Agents are systems where LLMs dynamically direct their own processes and tool usage, maintaining control over how they accomplish tasks”

關鍵特徵

Anthropic、OpenAI 和幾篇 arXiv 研究對這層的描述大致一致:模型自己動態規劃、自己選工具,從環境拿回饋(Anthropic 講的 “ground truth from environment”),多輪執行(“many turns”)直到滿足停止條件。

程式碼範例

# Level 3: Agent Loop
def agent_loop(task):
    while not is_complete():
        thought = llm.think(context)
        action = llm.select_tool(thought)
        result = execute(action)  # 環境回饋
        context.append((action, result))
    return context.final_answer

例子

  • Claude Code:單一自主 agent + 檔案/terminal 工具
  • SWE-bench 解題 agent:Anthropic 實作
  • Computer Use:Claude 操作電腦
  • Cursor Copilot:IDE 整合 agent

Level 4: Multi-Agent Systems(多智能體系統)

arXiv 2604.18071 定義:分析 70 個專案後,識別出 “subagent architecture” 為五個核心設計維度之一。

關鍵特徵

特徵說明
角色分工Planner / Coder / Reviewer / Tester
Agent 間通訊Agent A 輸出 → Agent B 輸入
任務分配Router / Orchestrator 決定誰做什麼
狀態共享Shared memory / Blackboard

架構模式(arXiv 發現)

  1. Hierarchical(層級式):Manager → Workers
  2. Peer-to-Peer(平等式):Agents 互相協商
  3. Blackboard(黑板式):共享工作區

程式碼範例

# Level 4: Multi-Agent
def multi_agent_system(task):
    plan = planner_agent(task)
    for subtask in plan:
        code = coder_agent(subtask)
        review = reviewer_agent(code)
        if review.approved:
            test = tester_agent(code)

例子

  • AutoGen:多 agent 對話協作
  • LangGraph Multi-Agent:有狀態的多 agent workflow
  • Claude Code + Subagents:主 agent spawn 子 agent

Level 5: Agent Harness(控制平面)

OpenAI 定義:“Harness engineering is the discipline of designing the scaffolding (context delivery, tool interfaces, planning artifacts, verification loops, memory systems, and sandboxes) that surrounds an AI agent”

五個核心設計維度(arXiv 2604.18071)

  1. Subagent architecture
  2. Context management
  3. Tool systems
  4. Safety mechanisms
  5. Orchestration

關鍵特徵

OpenAI、Anthropic、arXiv 對 harness 的共識大概是這幾件事:一個 control plane、會機械性強制執行的 policy gates(“mechanical enforcement”)、驗證迴圈、context 管理(OpenAI 強調的 “repository knowledge”)、可觀測性與審計,以及權限系統。

OpenAI 實作關鍵洞察

  • “Humans steer. Agents execute.”
  • “No manually-written code”:所有程式碼由 agent 生成
  • “Repository knowledge is the system of record”:知識庫存在 repo,不是放 Google Docs / Slack
  • “Agent legibility is the goal”:優化目標是讓 agent 看得懂

例子

  • OpenAI Codex Harness:百萬行 agent 生成程式碼的生產系統
  • SafeHarness(arXiv 2604.13630):生命週期整合安全架構
  • Microsoft Azure SRE Agent:處理 35,000+ production incidents

架構決策樹

你的需求是什麼?

├─ 簡單問答 / 資訊檢索? ── 是 ──→ L1: Augmented LLM
│                                  (來源:Anthropic)
└─ 否

   ├─ 任務可預先分解? ── 是 ──→ L2: Workflows
   │                            (來源:Anthropic, LangChain)
   └─ 否

      └─ 需要靈活性 / 自主性? ── 是

         └─ 任務太複雜需分工?

            ├─ 否 ──→ L3: Autonomous Agents
            │         (來源:Anthropic, OpenAI, arXiv)
            └─ 是 ── 需要生產級可控性?

                     ├─ 否 ──→ L4: Multi-Agent Systems
                     │         (來源:arXiv 2604.18071)
                     └─ 是 ──→ L5: Agent Harness
                               (來源:OpenAI, arXiv, Anthropic)

具體例子對照表

使用場景Level來源依據
ChatGPT 網頁版問問題L1Anthropic 定義
RAG 問答系統L1Anthropic “Augmented LLM”
Claude CodeL3Anthropic “Autonomous Agent”
Claude Code + SubagentL4arXiv “Subagent Architecture”
OpenAI Codex 生產系統L5OpenAI “Harness Engineering”
Microsoft Azure SRE AgentL5arXiv + Microsoft Tech Community

常見誤區

不算 Multi-Agent(L4)的情況

情況為什麼不算
Chain of Thought同一個 agent 在思考,無分工
單純 Tool Calling同一個 agent 在調用工具
單純 Handoff客服轉接,無協作

算 Multi-Agent 的條件

  1. 有角色分工(planner、coder、reviewer、tester)
  2. 有 Agent 間通訊(agent A 輸出 → agent B 輸入)
  3. 有任務分配機制(router / orchestrator 決定誰做什麼)
  4. 有狀態共享(shared memory / blackboard)

參考文獻

#來源機構日期研究方法
1Building Effective AgentsAnthropicDec 2024與數十個團隊合作的實證觀察
2Harness EngineeringOpenAIFeb 2026從 0 開始用 Codex 建構百萬行程式碼的實驗
3Architectural Design Decisions in AI Agent HarnessesarXivApr 2026分析 70 個公開 agent 系統的實證研究
4Building Effective AI Coding Agents for the TerminalarXivMar 2026OPENDEV 實作經驗
5The Anatomy of an Agent HarnessLangChain2026框架設計者視角