Repository: https://github.com/strands-agents/agent-sop Stars: 1015 | Forks: 96 | Language: Python | License: Apache-2.0 Tags: SOP, Workflows, Multi-step Homepage: https://aws.amazon.com/blogs/opensource/introducing-strands-agent-sops-natural-language-workflows-for-ai-agents/


1. 專案概覽 (Project Overview)

1.1 這是什麼

Agent SOP 是 Strands Agents 生態系中的自然語言工作流引擎 (Natural Language Workflow Engine)。它將複雜的多步驟任務定義為標準化的 Markdown 文件(副檔名 .sop.md),讓 AI Agent 能夠以一致且可靠的方式執行軟體開發、程式碼審查、文件撰寫等專業工作流程。

團隊內部暱稱為「Strands Operating Procedures (標準作業程序)」。

1.2 誰做的、為什麼做

Agent SOP 由 AWS 開源團隊開發,屬於 strands-agents 組織下的 12 個核心專案之一。其動機源自一個關鍵觀察:AI Agent 在執行複雜任務時經常偏離預期路徑。現有的 prompt engineering 手段要求撰寫者具備專業知識,且難以跨團隊共享和版本化。

Agent SOP 的解決方式是引入 RFC 2119 約束關鍵字 (Constraint Keywords) 系統——MUSTSHOULDMAY——將「建議性指引」轉化為「具強制力的操作規範」,使得:

  • 非工程師也能撰寫可執行的 Agent 工作流
  • 工作流可以版本控制、code review、跨團隊共享
  • 同一份 SOP 可透過 MCP Server、Python 模組、Cursor 指令、Agent Skill 等多種方式分發

1.3 在生態系中的定位

在 Strands Agents 的 12 個核心 repo 中,Agent SOP 扮演的是**「行為規範層 (Behavioral Specification Layer)」**的角色。如果把整個生態系比喻為一個作業系統:

角色對應 repo
核心引擎 (Kernel)sdk-python — Agent runtime
工具箱 (System Tools)tools — 內建工具集
行為規範 (Shell Scripts)agent-sop — 自然語言工作流
通訊協定 (IPC)mcp-server — MCP 整合
組裝器 (Builder)agent-builder — Agent 建構器
範例集 (Samples)samples — 範例程式碼

Agent SOP 不直接操作 LLM,而是提供結構化指令sdk-python 驅動的 Agent 執行。


2. 核心架構 (Core Architecture)

2.1 系統架構總覽


graph TB
    subgraph "SOP 定義層 (Definition Layer)"
        SOP1["code-assist.sop.md"]
        SOP2["pdd.sop.md"]
        SOP3["codebase-summary.sop.md"]
        SOP4["code-task-generator.sop.md"]
        SOP5["eval.sop.md"]
        CUSTOM["custom-workflow.sop.md"]
    end

    subgraph "分發層 (Distribution Layer)"
        MCP["MCP Server
FastMCP prompt server"] PYTHON["Python Module
import strands_agents_sops"] CURSOR["Cursor Commands
.cursor/commands/"] SKILLS["Agent Skills
SKILL.md format"] end subgraph "執行層 (Execution Layer)" KIRO["Kiro CLI"] CLAUDE["Claude Code"] CURSOR_IDE["Cursor IDE"] STRANDS["Strands Agent
(sdk-python)"] end SOP1 & SOP2 & SOP3 & SOP4 & SOP5 & CUSTOM --> MCP SOP1 & SOP2 & SOP3 & SOP4 & SOP5 & CUSTOM --> PYTHON SOP1 & SOP2 & SOP3 & SOP4 & SOP5 & CUSTOM --> CURSOR SOP1 & SOP2 & SOP3 & SOP4 & SOP5 & CUSTOM --> SKILLS MCP --> KIRO & CLAUDE PYTHON --> STRANDS CURSOR --> CURSOR_IDE SKILLS --> KIRO & CLAUDE & CURSOR_IDE

2.2 SOP 文件結構與解析流程

每個 .sop.md 檔案遵循嚴格的結構規範。以下是解析流程:


flowchart LR
    A["*.sop.md 檔案"] --> B{"解析 Overview"}
    B -->|"regex 擷取"| C["description 欄位"]
    B --> D{"解析 Parameters"}
    D -->|"required/optional"| E["參數定義"]
    D --> F{"解析 Steps"}
    F -->|"Constraints 區塊"| G["RFC 2119 約束"]

    G --> H{"MUST"}
    G --> I{"SHOULD"}
    G --> J{"MAY"}
    G --> K{"MUST NOT"}

    C & E & G --> L["XML 包裝"]
    L --> M[""]
    M --> N["注入 Agent System Prompt
或 MCP Prompt Response"]

2.3 關鍵原始碼解析

__init__.py — 動態模組載入

 1from pathlib import Path
 2
 3_sops_dir = Path(__file__).parent / "sops"
 4
 5for _md_file in _sops_dir.glob("*.sop.md"):
 6    if _md_file.is_file():
 7        # 將檔名轉為合法的 Python 識別符
 8        # 例如 code-assist.sop.md → code_assist
 9        _attr_name = (
10            _md_file.stem.removesuffix(".sop").replace("-", "_").replace(".", "_")
11        )
12        _content = _md_file.read_text(encoding="utf-8")
13
14        # 將 SOP 內容註冊為模組屬性
15        globals()[_attr_name] = _content
16
17        # 同時建立 wrapper function,產生 XML 格式
18        def _make_wrapper(content, name):
19            def wrapper(user_input: str = "") -> str:
20                return f"""<agent-sop name="{name}">
21<content>
22{content}
23</content>
24<user-input>
25{user_input}
26</user-input>
27</agent-sop>"""
28            return wrapper
29
30        globals()[f"{_attr_name}_with_input"] = _make_wrapper(_content, _sop_name)

這段程式碼的設計巧妙之處在於:

  1. 檔案即模組屬性:每個 .sop.md 自動成為可 import 的 Python 變數(例如 from strands_agents_sops import code_assist
  2. 雙重存取模式code_assist 取得原始 Markdown 字串,code_assist_with_input("my task") 取得 XML 包裝後的完整指令
  3. 零設定擴展:新增 SOP 只需放入 sops/ 目錄,無需修改任何程式碼

mcp.py — MCP Server 實作

 1from mcp.server.fastmcp import FastMCP
 2
 3def run_mcp_server(sop_paths: str | None = None):
 4    mcp = FastMCP("agent-sop-prompt-server")
 5    registered_sops = set()  # 追蹤已註冊的 SOP,實現 first-wins 行為
 6
 7    def register_sop(name: str, content: str, description: str):
 8        if name not in registered_sops:
 9            registered_sops.add(name)
10
11            def make_prompt_handler(sop_name: str, sop_content: str):
12                def get_prompt(user_input: str = "") -> str:
13                    return f"""Run this SOP:
14<agent-sop name="{sop_name}">
15<content>
16{sop_content}
17</content>
18<user-input>
19{user_input}
20</user-input>
21</agent-sop>"""
22                return get_prompt
23
24            # 註冊為 MCP prompt
25            mcp.prompt(name=name, description=description)(
26                make_prompt_handler(name, content)
27            )
28
29    # 外部 SOP 優先載入(higher precedence)
30    if sop_paths:
31        external_directories = expand_sop_paths(sop_paths)
32        external_sops = load_external_sops(external_directories)
33        for sop in external_sops:
34            register_sop(sop["name"], sop["content"], sop["description"])
35
36    # 內建 SOP 後載入(lower precedence)
37    sops_dir = Path(__file__).parent / "sops"
38    for md_file in sops_dir.glob("*.sop.md"):
39        # ... 略
40        register_sop(prompt_name, sop_content, description)
41
42    mcp.run()

核心設計:

  1. First-wins 語意:外部 SOP 先載入,同名的內建 SOP 會被跳過。這讓團隊可以 override 內建行為
  2. FastMCP prompt 註冊:每個 SOP 被註冊為一個 MCP prompt,AI 工具(Kiro、Claude Code)可透過 MCP 協定直接呼叫
  3. XML 封裝:所有 SOP 內容以 <agent-sop> XML tag 包裝,讓 LLM 能清楚區分指令與使用者輸入

3. 安裝與設定 (Installation & Setup)

3.1 先決條件

項目需求
Python>= 3.10
pip / uv最新版
Homebrew (macOS)選用,提供更方便的安裝方式

3.2 安裝方式

方式 A:Homebrew(推薦,macOS / Linux)

1brew install strands-agents-sops

方式 B:pip

1pip install strands-agents-sops

方式 C:uv(隔離環境,推薦用於開發)

1uv pip install strands-agents-sops

方式 D:從原始碼安裝

1git clone https://github.com/strands-agents/agent-sop.git
2cd agent-sop/python
3pip install -e .

3.3 驗證安裝

1# 確認 CLI 可用
2strands-agents-sops --help
3
4# 啟動 MCP Server 測試
5strands-agents-sops mcp
6# 應看到 MCP server 啟動訊息

3.4 搭配 Strands Agent 使用

如果要搭配完整的 Strands Agent 使用,還需安裝 SDK 和工具:

1pip install strands-agents strands-agents-tools strands-agents-sops

3.5 MCP 設定(各 IDE 整合)

Kiro CLI 設定(~/.kiro/settings/mcp.json

1{
2  "mcpServers": {
3    "agent-sops": {
4      "command": "strands-agents-sops",
5      "args": ["mcp"],
6      "env": {}
7    }
8  }
9}

Claude Code 設定(.claude/settings.json 或全域設定)

1{
2  "mcpServers": {
3    "agent-sops": {
4      "command": "strands-agents-sops",
5      "args": ["mcp"]
6    }
7  }
8}

載入自訂 SOP 目錄

1{
2  "mcpServers": {
3    "agent-sops": {
4      "command": "strands-agents-sops",
5      "args": ["mcp", "--sop-paths", "~/my-sops:/team/shared-sops"],
6      "env": {}
7    }
8  }
9}

路徑以 : 分隔(Unix)或 ; 分隔(Windows),支援 ~ 展開與相對路徑。

3.6 Cursor IDE 設定

1# 從 SOP 產生 Cursor 指令
2strands-agents-sops commands --type cursor
3
4# 指定輸出目錄
5strands-agents-sops commands --type cursor --output-dir .cursor/commands
6
7# 含自訂 SOP
8strands-agents-sops commands --type cursor --sop-paths ~/my-sops

產生後,在 Cursor 中使用 /code-assist 即可觸發對應的 SOP。


4. 使用方式與程式碼範例 (Usage & Code Examples)

4.1 範例一:以 Python SDK 使用 Code Assist SOP

這是最直接的使用方式——將 SOP 作為 Agent 的 System Prompt (系統提示)。

 1from strands import Agent
 2from strands_tools import editor, shell
 3from strands_agents_sops import code_assist
 4
 5# 建立 Agent,以 code_assist SOP 作為系統指令
 6agent = Agent(
 7    system_prompt=code_assist,    # SOP 的 Markdown 字串直接注入
 8    tools=[editor, shell]         # 提供檔案編輯和 shell 執行工具
 9)
10
11# 啟動 SOP 流程
12agent("Start code-assist sop")
13
14# 互動式循環:使用者逐步提供參數和確認
15while True:
16    user_input = input("\nInput: ")
17    agent(user_input)

逐行解說:

  • from strands_agents_sops import code_assist__init__.py 的動態載入機制會將 code-assist.sop.md 的完整內容作為 code_assist 字串變數匯出
  • system_prompt=code_assist:將整份 SOP(數百行的結構化 Markdown)注入為 Agent 的系統提示,Agent 會嚴格遵循其中的步驟和約束
  • tools=[editor, shell]:Code Assist SOP 需要檔案編輯和命令執行能力才能完成 TDD 工作流
  • "Start code-assist sop":觸發 Agent 進入 SOP 的 Step 1(Setup),開始詢問必要參數

4.2 範例二:使用 _with_input 帶入使用者參數

 1from strands import Agent
 2from strands_tools import editor, shell
 3from strands_agents_sops import code_assist_with_input
 4
 5# 建立基礎 Agent(不預設 SOP)
 6agent = Agent(tools=[editor, shell])
 7
 8# 使用 _with_input wrapper,將使用者需求一次帶入
 9response = agent(
10    code_assist_with_input(
11        "Implement a REST API endpoint for user authentication "
12        "using JWT tokens with refresh token rotation"
13    )
14)

逐行解說:

  • code_assist_with_input(user_input):呼叫 wrapper function,產生以下 XML 結構:
1<agent-sop name="code-assist">
2<content>
3[完整的 code-assist.sop.md 內容]
4</content>
5<user-input>
6Implement a REST API endpoint for user authentication...
7</user-input>
8</agent-sop>
  • 與範例一的差別在於:使用者的 task description 在第一次呼叫時就隨 SOP 一起注入,Agent 可以直接開始處理,不需先問「你的 task_description 是什麼?」

4.3 範例三:撰寫自訂 SOP

假設團隊需要一個「PR Review SOP」,可以建立 pr-review.sop.md

 1# PR Review
 2
 3## Overview
 4This SOP guides AI agents through a structured pull request review process,
 5focusing on code quality, security, performance, and adherence to team standards.
 6
 7## Parameters
 8- **pr_url** (required): The URL or identifier of the pull request to review
 9- **review_focus** (optional, default: "general"): Focus area - "general", "security", "performance"
10- **codebase_context** (optional): Path to relevant architecture docs
11
12## Steps
13
14### 1. Context Gathering
15Retrieve the PR diff, commit messages, and related issue descriptions.
16
17**Constraints:**
18- You MUST read the complete diff before making any assessment
19- You MUST identify the PR's stated purpose from the description or linked issues
20- You MUST NOT review files unrelated to the PR's changes
21- You SHOULD check if the PR affects critical paths (auth, payments, data migration)
22
23### 2. Structural Review
24Evaluate the overall design and architecture of the changes.
25
26**Constraints:**
27- You MUST verify the changes align with existing architecture patterns
28- You SHOULD flag any new dependencies or external service integrations
29- You MAY suggest alternative approaches if the current design has scalability concerns
30- You MUST NOT suggest rewrites of working code unless there is a clear defect
31
32### 3. Line-by-Line Review
33Perform detailed code inspection.
34
35**Constraints:**
36- You MUST check for common vulnerabilities (SQL injection, XSS, SSRF)
37- You MUST verify error handling covers edge cases
38- You SHOULD identify any code that violates DRY principles
39- You SHOULD check test coverage for new code paths
40- You MAY suggest style improvements but MUST NOT block on style alone
41
42### 4. Summary and Recommendation
43Provide a structured review summary.
44
45**Constraints:**
46- You MUST categorize findings as CRITICAL, HIGH, MEDIUM, or LOW severity
47- You MUST provide an overall recommendation: APPROVE, REQUEST_CHANGES, or COMMENT
48- You MUST include actionable next steps for each finding
49- You SHOULD acknowledge well-written code sections

部署自訂 SOP 的三種方式:

1# 1. 透過 MCP Server 載入
2strands-agents-sops mcp --sop-paths ~/my-sops
3
4# 2. 轉為 Cursor 指令
5strands-agents-sops commands --type cursor --sop-paths ~/my-sops
6
7# 3. 轉為 Agent Skill
8strands-agents-sops skills --output-dir ./skills --sop-paths ~/my-sops

4.4 範例四:Prompt-Driven Development (PDD) 全流程

PDD 是 Agent SOP 中最完整的工作流,從粗略想法到完整設計文件:

 1from strands import Agent
 2from strands_tools import editor, shell, http_request
 3from strands_agents_sops import pdd
 4
 5# PDD 需要更多工具來做研究和文件操作
 6agent = Agent(
 7    system_prompt=pdd,
 8    tools=[editor, shell, http_request]
 9)
10
11# 啟動 PDD — Agent 會引導你完成以下階段:
12# 1. Create Project Structure    → 建立 .agents/planning/ 目錄結構
13# 2. Initial Process Planning    → 決定先做 requirements 還是 research
14# 3. Requirements Clarification  → 一次問一個問題,逐步釐清需求
15# 4. Research                    → 蒐集技術資訊、競品分析
16# 5. Design Creation             → 撰寫完整設計文件 + Mermaid 圖表
17# 6. Implementation Planning     → 拆解為可執行的實作步驟
18
19agent("Start PDD with rough idea: Build a real-time collaborative "
20      "markdown editor with conflict resolution")

PDD 產出的目錄結構:

 1.agents/
 2└── planning/
 3    └── 2026-06-18-collaborative-editor/
 4        ├── rough-idea.md              # 原始想法
 5        ├── idea-honing.md             # 需求釐清 Q&A
 6        ├── research/
 7        │   ├── existing-code.md       # 現有程式碼分析
 8        │   └── technologies.md        # 技術選型研究
 9        ├── design/
10        │   ├── system-design.md       # 系統設計文件
11        │   └── api-design.md          # API 設計
12        └── implementation/
13            └── plan.md                # 實作計畫 + checklist

5. 進階功能 (Advanced Features)

5.1 RFC 2119 約束系統 (Constraint System)

Agent SOP 的核心創新在於將 RFC 2119 的標準化關鍵字引入 AI 指令:

關鍵字語意Agent 行為
MUST / REQUIRED絕對要求Agent 必須執行,否則視為失敗
MUST NOT / SHALL NOT絕對禁止Agent 絕不可執行
SHOULD / RECOMMENDED強烈建議預設遵循,有合理理由可例外
SHOULD NOT / NOT RECOMMENDED強烈不建議預設避免,有合理理由可例外
MAY / OPTIONAL完全可選Agent 自行判斷是否執行

否定約束的撰寫規範要求必須附帶理由

1# 好的寫法 — 附帶理由
2- You MUST NOT delete files without confirmation because this could result in permanent data loss
3
4# 不好的寫法 — 缺少理由
5- You MUST NOT delete files

5.2 外部 SOP 載入機制 (External SOP Loading)

utils.py 中的 load_external_sops() 實作了一套安全的外部 SOP 發現機制:

 1def load_external_sops(sop_directories: list[Path]) -> list[dict[str, Any]]:
 2    external_sops = []
 3    for directory in sop_directories:
 4        if not directory.exists():
 5            logger.warning(f"SOP directory does not exist: {directory}")
 6            continue
 7        for sop_file in directory.glob("*.sop.md"):
 8            sop_content = sop_file.read_text(encoding="utf-8")
 9            # 必須包含 ## Overview 段落,否則跳過
10            overview_match = re.search(
11                r"## Overview\s*\n(.*?)(?=\n##|\n#|\Z)", sop_content, re.DOTALL
12            )
13            if not overview_match:
14                logger.warning(f"No Overview section found in {sop_file}")
15                continue
16            # ...
17    return external_sops

設計要點:

  • 副檔名門檻:只有 .sop.md 結尾的檔案才會被識別
  • 結構驗證:必須包含 ## Overview 段落,否則跳過並記錄警告
  • 容錯機制:目錄不存在、非目錄、讀取失敗等都以 warning 處理,不會中斷整個系統
  • First-wins 語意:外部 SOP 優先於內建 SOP,同名只註冊第一個

5.3 多格式輸出 (Multi-Format Output)

CLI 支援四種輸出模式,對應不同的 AI 工具生態系:

 1# 1. MCP Server — 適用 Kiro CLI、Claude Code 等支援 MCP 的工具
 2strands-agents-sops mcp
 3
 4# 2. Agent Skills — 產生含 frontmatter 的 SKILL.md 檔案
 5strands-agents-sops skills --output-dir ./skills
 6
 7# 3. Cursor Commands — 產生 .cursor/commands/ 下的指令檔案
 8strands-agents-sops commands --type cursor
 9
10# 4. Rule Output — 輸出 SOP 撰寫格式規範
11strands-agents-sops rule

Skill 生成範例(skills.py 中的 _create_skill_file):

 1def _create_skill_file(output_path, skill_name, content, description):
 2    skill_dir = output_path / skill_name
 3    skill_dir.mkdir(parents=True, exist_ok=True)
 4
 5    frontmatter = f"""---
 6name: {skill_name}
 7description: {description}
 8---
 9
10"""
11    skill_file = skill_dir / "SKILL.md"
12    skill_file.write_text(frontmatter + content)

這讓每個 SOP 自動變成一個符合 Claude Code / Kiro skill 格式的文件,可直接放入 .claude/skills/skills/ 目錄。

5.4 PDD 家族工作流串接

四個內建 SOP 設計為可串接的工作流 (Workflow Chain):

1                    +----- [3] code-task-generator ----+
2                    |    將 PDD plan 拆為 task 檔案     |
3                    |                                   v
4[1] codebase-summary → [2] pdd → [3] tasks → [4] code-assist
5    分析現有程式碼        設計規劃     任務拆解      TDD 實作

串接時,它們共用 .agents/ 目錄結構:

SOP輸出目錄建議 Git 策略
codebase-summary.agents/summary/Always commit
pdd.agents/planning/{project}/Often commit
code-task-generator.agents/tasks/{project}/Optionally commit
code-assist.agents/scratchpad/{project}/Add to .gitignore

5.5 Interactive vs Auto 模式

Code Assist SOP 支援兩種執行模式:

Interactive Mode (互動模式)

  • 每一步驟前呈現行動方案並請求確認
  • 多種方案時解釋利弊並詢問偏好
  • 在關鍵決策點暫停並說明推理過程
  • 適合學習或高風險任務

Auto Mode (全自動模式)

  • 全程自主執行,不需使用者確認
  • 所有決策、假設、推理都記錄在 progress.md
  • 完成後提供完整摘要
  • 適合已明確定義的任務

6. Agent 可呼叫性分析 (Agent Callability)

6.1 CLI 介面

1# 完整指令參考
2strands-agents-sops --help
3
4# 子指令
5strands-agents-sops mcp [--sop-paths PATH]        # 啟動 MCP Server
6strands-agents-sops skills [--output-dir DIR]      # 產生 Agent Skills
7strands-agents-sops commands --type cursor         # 產生 Cursor 指令
8strands-agents-sops rule                           # 輸出 SOP 格式規範

6.2 MCP 整合

Agent SOP 透過 FastMCP 將每個 SOP 註冊為 MCP prompt:

  • 協定:MCP (Model Context Protocol)
  • 傳輸方式:stdio(由 MCP client 啟動 subprocess)
  • 暴露方式:每個 SOP 作為一個 named prompt,帶有 description 和 user_input 參數

在 Claude Code 中呼叫:

1/strands-agents-sops:codebase-summary

在 Kiro 中呼叫:

1@codebase-summary

6.3 Python API

1# 直接 import SOP 內容
2from strands_agents_sops import code_assist, pdd, codebase_summary
3
4# 使用 with_input wrapper
5from strands_agents_sops import code_assist_with_input
6
7# 取得 SOP 格式規範
8from strands_agents_sops import get_sop_format

6.4 可呼叫性摘要

整合方式適用場景支援的 AI 工具
MCP ServerIDE 內直接呼叫Kiro CLI, Claude Code
Python Module程式碼中建構 AgentStrands Agent, 任何 Python Agent
Cursor CommandsCursor IDE 工作流Cursor
Agent Skills跨平台 Skill 格式任何支援 SKILL.md 的工具

7. 與生態系的關係 (Ecosystem Relationships)

7.1 Strands Agents 生態系地圖

Agent SOP 是 strands-agents 組織下 12 個核心專案之一。以下是它與其他專案的關係:


graph TD
    SDK["sdk-python
Agent 核心 SDK"] TOOLS["tools
內建工具集"] SOP["agent-sop
自然語言工作流"] MCP_SRV["mcp-server
MCP 整合"] BUILDER["agent-builder
Agent 建構器"] SAMPLES["samples
範例程式碼"] EVALS["evals
評估框架"] SDK -->|"runtime 執行"| SOP TOOLS -->|"提供 editor, shell"| SOP SOP -->|"eval SOP 使用"| EVALS SOP -->|"MCP 分發"| MCP_SRV SOP -->|"使用範例"| SAMPLES BUILDER -->|"建構使用 SOP 的 Agent"| SOP style SOP fill:#f9f,stroke:#333,stroke-width:3px

7.2 依賴關係詳解

相關 repo關係類型說明
sdk-pythonRuntime 依賴Agent SOP 的 SOP 字串注入為 Agent()system_prompt,由 SDK 驅動 LLM 執行
tools工具依賴Code Assist 等 SOP 需要 editorshell 等工具才能操作檔案和執行命令
mcp-server通訊協定共享兩者都實作 MCP,但 agent-sop 專注於 prompt 暴露,mcp-server 專注於工具暴露
evals評估整合eval.sop.md 直接引用 Strands Evals SDK 來執行 Agent 品質評估
agent-builder上層消費者Agent Builder 可整合 SOP 作為預設工作流模板
samples範例展示Samples repo 包含使用 SOP 的完整範例程式

7.3 與 Kiro CLI 的關係

Agent SOP 與 AWS 的 Kiro CLI(AI-native IDE)有深度整合:

  • SOP 可透過 MCP 自動被 Kiro 發現
  • PDD 的 .agents/ 目錄結構與 Kiro 的 /context add 指令相容
  • Kiro 內可用 @sop-name 語法直接呼叫 SOP

8. 優缺點分析 (Strengths & Limitations)

8.1 優勢

面向說明
自然語言定義不需 prompt engineering 專業知識,用標準 Markdown 撰寫,降低入門門檻
RFC 2119 約束用標準化關鍵字(MUST/SHOULD/MAY)精確控制 Agent 行為,避免模糊指引
版本控制友好純 Markdown 文件,可 Git 追蹤、code review、CI/CD 整合
多通路分發同一份 SOP 可透過 MCP、Python、Cursor、Skill 四種方式使用
First-wins 覆寫外部 SOP 可 override 內建行為,支援團隊客製化
PDD 全流程從粗略想法到完整設計的端到端工作流,含研究、需求、設計、實作四階段
極簡依賴只依賴 mcp>=1.20.0,安裝輕量

8.2 限制

面向說明
LLM 遵從度約束的執行仍依賴 LLM 的理解力;不是強制執行,而是「強力建議」
SOP 數量有限目前內建只有 5 個 SOP,覆蓋面主要在軟體開發領域
除錯困難當 Agent 偏離 SOP 步驟時,缺少結構化的除錯和追蹤機制
無狀態管理SOP 不追蹤執行進度;中斷後需從頭開始(PDD 除外,有 checklist)
單一語言SOP 內容主要以英語撰寫,對非英語團隊的 LLM 遵從度可能降低
IDE 整合侷限目前 Cursor commands 支援最完整,其他 IDE 需透過 MCP 間接使用

8.3 與本專案(AIKT)的比較

Agent SOP 的設計哲學與本專案(AI Knowledge Template)的 Skill 系統有相似之處:

面向Agent SOPAIKT Skill
格式.sop.md(Markdown + 約束)SKILL.md(Markdown + frontmatter)
約束語言RFC 2119(MUST/SHOULD/MAY)自然語言 + 觸發規則表
分發MCP / Python / Cursor / Skill.claude/skills/ 目錄
參數化Parameters 段落 + 型別標註前綴觸發(qd:paper:
串接PDD 家族共用 .agents/Layer 分流表 + Cross-Layer 規則

9. 實戰應用場景 (Real-world Use Cases)

9.1 場景一:新進工程師 Onboarding

問題:新進工程師需要花 2-3 天理解大型 codebase 的架構和慣例。

解法:使用 codebase-summary SOP 自動產生結構化文件。

 1# 在 Kiro CLI 中
 2@codebase-summary
 3
 4# Agent 會:
 5# 1. 掃描整個 codebase 結構
 6# 2. 識別架構模式、技術堆疊、關鍵介面
 7# 3. 產生 Mermaid 圖表的系統架構圖
 8# 4. 輸出到 .agents/summary/
 9#    - index.md(導覽索引,AI 助手的入口點)
10#    - architecture.md(系統架構)
11#    - components.md(模組說明)
12#    - interfaces.md(API 與整合點)
13#    - workflows.md(關鍵流程)
14#    - AGENTS.md(AI 助手專用的 README)

效果:Onboarding 時間從 2-3 天縮短到數小時,且產出的文件可以被後續的 AI 工作流重複利用。

9.2 場景二:TDD 導向的功能開發

問題:團隊希望所有新功能都遵循 TDD 流程,但工程師常因時間壓力跳過測試。

解法:使用 PDD + Code Task Generator + Code Assist 三個 SOP 串接。

 1from strands import Agent
 2from strands_tools import editor, shell
 3from strands_agents_sops import pdd, code_task_generator_with_input, code_assist
 4
 5# Phase 1: 設計規劃
 6design_agent = Agent(system_prompt=pdd, tools=[editor, shell])
 7design_agent("Build a rate limiter middleware with sliding window algorithm")
 8
 9# Phase 2: 任務拆解(從 PDD 的 plan.md 自動拆解)
10task_agent = Agent(system_prompt=code_task_generator_with_input(
11    ".agents/planning/2026-06-18-rate-limiter/implementation/plan.md"
12), tools=[editor, shell])
13task_agent("Generate tasks from this plan")
14
15# Phase 3: 逐任務 TDD 實作
16impl_agent = Agent(system_prompt=code_assist, tools=[editor, shell])
17impl_agent("Start code-assist sop for task: "
18           ".agents/tasks/2026-06-18-rate-limiter/step01/task-01.code-task.md")

效果:Code Assist SOP 的約束規定 MUST 先寫測試再寫實作,MUST NOT 在測試通過前進入下一步。Agent 被強制遵循 RED-GREEN-REFACTOR 流程。

9.3 場景三:跨團隊 Agent 品質評估

問題:多個團隊各自開發 Agent,缺少統一的評估標準和流程。

解法:使用 eval SOP 搭配 Strands Evals SDK。

1# 在 Kiro CLI 或 Claude Code 中
2@eval
3
4# Agent 會引導你完成:
5# 1. Setup — 驗證環境、建立 eval/ 目錄
6# 2. Plan — 設計評估策略(哪些面向、哪些指標)
7# 3. Generate Test Data — 自動或半自動產生測試案例(JSONL 格式)
8# 4. Execute — 跑評估腳本,收集結果
9# 5. Analyze — 分析結果、產生報告、提出改善建議

效果:評估流程標準化後,不同團隊的 Agent 品質可以橫向比較,且評估腳本可以整合到 CI/CD 中持續監控。


附錄:CLI 指令速查表

指令說明
strands-agents-sops mcp啟動 MCP Server(預設行為)
strands-agents-sops mcp --sop-paths ~/sops載入外部 SOP 後啟動 MCP
strands-agents-sops skills產生 Agent Skill 檔案
strands-agents-sops skills --output-dir ./my-skills指定 Skill 輸出目錄
strands-agents-sops commands --type cursor產生 Cursor IDE 指令
strands-agents-sops rule輸出 SOP 撰寫格式規範

附錄:內建 SOP 一覽

SOP 名稱用途典型使用情境
codebase-summary程式碼庫分析與文件生成新專案 onboarding、文件建立
pddPrompt-Driven Development從粗略想法到完整設計文件
code-task-generator智慧任務拆解Sprint 規劃、需求分析
code-assistTDD 導向的程式碼實作功能開發、Bug 修復、重構
evalAI Agent 自動化評估品質評估、測試資料產生

附錄:SOP 格式規範速查

 1# SOP 標題
 2
 3## Overview
 4簡述用途和適用場景。
 5
 6## Parameters
 7- **param_name** (required): 必要參數說明
 8- **param_name** (optional, default: "value"): 選用參數說明
 9
10## Steps
11### 1. 步驟名稱
12自然語言描述。
13
14**Constraints:**
15- You MUST [必要行為]
16- You SHOULD [建議行為]
17- You MAY [選用行為]
18- You MUST NOT [禁止行為] because [理由]
19
20## Examples
21具體的輸入輸出範例。
22
23## Troubleshooting
24常見問題與解決方式。