agent-architecture-analysis

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

12-Factor Agents Compliance Analysis

12-Factor Agents合规性分析

Reference: 12-Factor Agents

Input Parameters

输入参数

ParameterDescriptionRequired
docs_path
Path to documentation directory (for existing analyses)Optional
codebase_path
Root path of the codebase to analyzeRequired
参数描述是否必填
docs_path
文档目录路径(用于已有分析)可选
codebase_path
待分析代码库的根路径必填

Analysis Framework

分析框架

Factor 1: Natural Language to Tool Calls

要素1:自然语言转工具调用

Principle: Convert natural language inputs into structured, deterministic tool calls using schema-validated outputs.
Search Patterns:
bash
undefined
原则: 使用模式验证的输出,将自然语言输入转换为结构化、确定性的工具调用。
搜索模式:
bash
undefined

Look for Pydantic schemas

查找Pydantic模式

grep -r "class.BaseModel" --include=".py" grep -r "TaskDAG|TaskResponse|ToolCall" --include="*.py"
grep -r "class.BaseModel" --include=".py" grep -r "TaskDAG|TaskResponse|ToolCall" --include="*.py"

Look for JSON schema generation

查找JSON模式生成

grep -r "model_json_schema|json_schema" --include="*.py"
grep -r "model_json_schema|json_schema" --include="*.py"

Look for structured output generation

查找结构化输出生成

grep -r "output_type|response_model" --include="*.py"

**File Patterns:** `**/agents/*.py`, `**/schemas/*.py`, `**/models/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | All LLM outputs use Pydantic/dataclass schemas with validators |
| **Partial** | Some outputs typed, but dict returns or unvalidated strings exist |
| **Weak** | LLM returns raw strings parsed manually or with regex |

**Anti-patterns:**
- `json.loads(llm_response)` without schema validation
- `output.split()` or regex parsing of LLM responses
- `dict[str, Any]` return types from agents
- No validation between LLM output and handler execution

---
grep -r "output_type|response_model" --include="*.py"

**文件模式:** `**/agents/*.py`, `**/schemas/*.py`, `**/models/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 所有LLM输出使用带验证器的Pydantic/dataclass模式 |
| **部分合规** | 部分输出已类型化,但存在字典返回或未验证的字符串 |
| **弱合规** | LLM返回原始字符串,需手动解析或使用正则表达式解析 |

**反模式:**
- `json.loads(llm_response)` 未搭配模式验证
- 使用`output.split()`或正则表达式解析LLM响应
- Agent返回`dict[str, Any]`类型
- LLM输出与处理器执行之间无验证环节

---

Factor 2: Own Your Prompts

要素2:自主管理提示词

Principle: Treat prompts as first-class code you control, version, and iterate on.
Search Patterns:
bash
undefined
原则: 将提示词视为你可控、可版本化、可迭代的一等代码。
搜索模式:
bash
undefined

Look for embedded prompts

查找嵌入式提示词

grep -r "SYSTEM_PROMPT|system_prompt" --include="*.py" grep -r '""".You are' --include=".py"
grep -r "SYSTEM_PROMPT|system_prompt" --include="*.py" grep -r '""".You are' --include=".py"

Look for template systems

查找模板系统

grep -r "jinja|Jinja|render_template" --include=".py" find . -name ".jinja2" -o -name "*.j2"
grep -r "jinja|Jinja|render_template" --include=".py" find . -name ".jinja2" -o -name "*.j2"

Look for prompt directories

查找提示词目录

find . -type d -name "prompts"

**File Patterns:** `**/prompts/**`, `**/templates/**`, `**/agents/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Prompts in separate files, templated (Jinja2), versioned |
| **Partial** | Prompts as module constants, some parameterization |
| **Weak** | Prompts hardcoded inline in functions, f-strings only |

**Anti-patterns:**
- `f"You are a {role}..."` inline in agent methods
- Prompts mixed with business logic
- No way to iterate on prompts without code changes
- No prompt versioning or A/B testing capability

---
find . -type d -name "prompts"

**文件模式:** `**/prompts/**`, `**/templates/**`, `**/agents/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 提示词存储在独立文件中,使用Jinja2模板化,支持版本控制 |
| **部分合规** | 提示词作为模块常量,具备一定参数化能力 |
| **弱合规** | 提示词硬编码在函数内联中,仅使用f-string |

**反模式:**
- 代理方法内联使用`f"You are a {role}..."`
- 提示词与业务逻辑混合
- 无需修改代码即可迭代提示词的方式
- 无提示词版本控制或A/B测试能力

---

Factor 3: Own Your Context Window

要素3:自主管理上下文窗口

Principle: Control how history, state, and tool results are formatted for the LLM.
Search Patterns:
bash
undefined
原则: 控制历史记录、状态和工具结果如何为LLM格式化。
搜索模式:
bash
undefined

Look for context/message management

查找上下文/消息管理

grep -r "AgentMessage|ChatMessage|messages" --include=".py" grep -r "context_window|context_compiler" --include=".py"
grep -r "AgentMessage|ChatMessage|messages" --include=".py" grep -r "context_window|context_compiler" --include=".py"

Look for custom serialization

查找自定义序列化

grep -r "to_xml|to_context|serialize" --include="*.py"
grep -r "to_xml|to_context|serialize" --include="*.py"

Look for token management

查找令牌管理

grep -r "token_count|max_tokens|truncate" --include="*.py"

**File Patterns:** `**/context/*.py`, `**/state/*.py`, `**/core/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Custom context format, token optimization, typed events, compaction |
| **Partial** | Basic message history with some structure |
| **Weak** | Raw message accumulation, standard OpenAI format only |

**Anti-patterns:**
- Unbounded message accumulation
- Large artifacts embedded inline (diffs, files)
- No agent-specific context filtering
- Same context for all agent types

---
grep -r "token_count|max_tokens|truncate" --include="*.py"

**文件模式:** `**/context/*.py`, `**/state/*.py`, `**/core/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 自定义上下文格式、令牌优化、类型化事件、压缩机制 |
| **部分合规** | 具备基本的结构化消息历史 |
| **弱合规** | 原始消息累加,仅使用标准OpenAI格式 |

**反模式:**
- 无限制的消息累加
- 大型工件(差异、文件)内联嵌入
- 无Agent特定的上下文过滤
- 所有Agent类型使用相同上下文

---

Factor 4: Tools Are Structured Outputs

要素4:工具作为结构化输出

Principle: Tools produce schema-validated JSON that triggers deterministic code, not magic function calls.
Search Patterns:
bash
undefined
原则: 工具生成模式验证的JSON,触发确定性代码,而非魔术函数调用。
搜索模式:
bash
undefined

Look for tool/response schemas

查找工具/响应模式

grep -r "class.Response.BaseModel" --include=".py" grep -r "ToolResult|ToolOutput" --include=".py"
grep -r "class.Response.BaseModel" --include=".py" grep -r "ToolResult|ToolOutput" --include=".py"

Look for deterministic handlers

查找确定性处理器

grep -r "def handle_|def execute_" --include="*.py"
grep -r "def handle_|def execute_" --include="*.py"

Look for validation layer

查找验证层

grep -r "model_validate|parse_obj" --include="*.py"

**File Patterns:** `**/tools/*.py`, `**/handlers/*.py`, `**/agents/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | All tool outputs schema-validated, handlers type-safe |
| **Partial** | Most tools typed, some loose dict returns |
| **Weak** | Tools return arbitrary dicts, no validation layer |

**Anti-patterns:**
- Tool handlers that directly execute LLM output
- `eval()` or `exec()` on LLM-generated code
- No separation between decision (LLM) and execution (code)
- Magic method dispatch based on string matching

---
grep -r "model_validate|parse_obj" --include="*.py"

**文件模式:** `**/tools/*.py`, `**/handlers/*.py`, `**/agents/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 所有工具输出均经过模式验证,处理器类型安全 |
| **部分合规** | 大部分工具已类型化,存在少量松散字典返回 |
| **弱合规** | 工具返回任意字典,无验证层 |

**反模式:**
- 工具处理器直接执行LLM输出
- 对LLM生成的代码使用`eval()`或`exec()`
- 决策(LLM)与执行(代码)无分离
- 基于字符串匹配的魔术方法调度

---

Factor 5: Unify Execution State

要素5:统一执行状态

Principle: Merge execution state (step, retries) with business state (messages, results).
Search Patterns:
bash
undefined
原则: 将执行状态(步骤、重试)与业务状态(消息、结果)合并。
搜索模式:
bash
undefined

Look for state models

查找状态模型

grep -r "ExecutionState|WorkflowState|Thread" --include="*.py"
grep -r "ExecutionState|WorkflowState|Thread" --include="*.py"

Look for dual state systems

查找双状态系统

grep -r "checkpoint|MemorySaver" --include=".py" grep -r "sqlite|database|repository" --include=".py"
grep -r "checkpoint|MemorySaver" --include=".py" grep -r "sqlite|database|repository" --include=".py"

Look for state reconstruction

查找状态重构

grep -r "load_state|restore|reconstruct" --include="*.py"

**File Patterns:** `**/state/*.py`, `**/models/*.py`, `**/database/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Single serializable state object with all execution metadata |
| **Partial** | State exists but split across systems (memory + DB) |
| **Weak** | Execution state scattered, requires multiple queries to reconstruct |

**Anti-patterns:**
- Retry count stored separately from task state
- Error history in logs but not in state
- LangGraph checkpoints + separate database storage
- No unified event thread

---
grep -r "load_state|restore|reconstruct" --include="*.py"

**文件模式:** `**/state/*.py`, `**/models/*.py`, `**/database/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 单一可序列化状态对象,包含所有执行元数据 |
| **部分合规** | 状态存在但分散在多个系统中(内存+数据库) |
| **弱合规** | 执行状态分散,需要多次查询才能重构 |

**反模式:**
- 重试计数与任务状态分开存储
- 错误历史仅存在于日志中,未纳入状态
- LangGraph检查点+独立数据库存储
- 无统一事件线程

---

Factor 6: Launch/Pause/Resume

要素6:启动/暂停/恢复

Principle: Agents support simple APIs for launching, pausing at any point, and resuming.
Search Patterns:
bash
undefined
原则: Agent支持简单的API用于启动、在任意点暂停以及恢复。
搜索模式:
bash
undefined

Look for REST endpoints

查找REST端点

grep -r "@router.post|@app.post" --include=".py" grep -r "start_workflow|pause|resume" --include=".py"
grep -r "@router.post|@app.post" --include=".py" grep -r "start_workflow|pause|resume" --include=".py"

Look for interrupt mechanisms

查找中断机制

grep -r "interrupt_before|interrupt_after" --include="*.py"
grep -r "interrupt_before|interrupt_after" --include="*.py"

Look for webhook handlers

查找Webhook处理器

grep -r "webhook|callback" --include="*.py"

**File Patterns:** `**/routes/*.py`, `**/api/*.py`, `**/orchestrator/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | REST API + webhook resume, pause at any point including mid-tool |
| **Partial** | Launch/pause/resume exists but only at coarse-grained points |
| **Weak** | CLI-only launch, no pause/resume capability |

**Anti-patterns:**
- Blocking `input()` or `confirm()` calls
- No way to resume after process restart
- Approval only at plan level, not per-tool
- No webhook-based resume from external systems

---
grep -r "webhook|callback" --include="*.py"

**文件模式:** `**/routes/*.py`, `**/api/*.py`, `**/orchestrator/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | REST API + Webhook恢复,可在任意点(包括工具执行中)暂停 |
| **部分合规** | 存在启动/暂停/恢复功能,但仅支持粗粒度节点 |
| **弱合规** | 仅支持CLI启动,无暂停/恢复能力 |

**反模式:**
- 阻塞式`input()`或`confirm()`调用
- 进程重启后无法恢复
- 仅在计划层面批准,而非每个工具
- 无基于Webhook的外部系统恢复方式

---

Factor 7: Contact Humans with Tools

要素7:通过工具联系人类

Principle: Human contact is a tool call with question, options, and urgency.
Search Patterns:
bash
undefined
原则: 人类联系是包含问题、选项和紧急程度的工具调用。
搜索模式:
bash
undefined

Look for human input mechanisms

查找人类输入机制

grep -r "typer.confirm|input(|prompt(" --include=".py" grep -r "request_human_input|human_contact" --include=".py"
grep -r "typer.confirm|input(|prompt(" --include=".py" grep -r "request_human_input|human_contact" --include=".py"

Look for approval patterns

查找审批模式

grep -r "approval|approve|reject" --include="*.py"
grep -r "approval|approve|reject" --include="*.py"

Look for structured question formats

查找结构化问题格式

grep -r "question.options|HumanInputRequest" --include=".py"

**File Patterns:** `**/agents/*.py`, `**/tools/*.py`, `**/orchestrator/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | `request_human_input` tool with question/options/urgency/format |
| **Partial** | Approval gates exist but hardcoded in graph structure |
| **Weak** | Blocking CLI prompts, no tool-based human contact |

**Anti-patterns:**
- `typer.confirm()` in agent code
- Human contact hardcoded at specific graph nodes
- No way for agents to ask clarifying questions
- Single response format (yes/no only)

---
grep -r "question.options|HumanInputRequest" --include=".py"

**文件模式:** `**/agents/*.py`, `**/tools/*.py`, `**/orchestrator/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | `request_human_input`工具包含问题/选项/紧急程度/格式 |
| **部分合规** | 存在审批门限,但硬编码在图结构中 |
| **弱合规** | 阻塞式CLI提示,无基于工具的人类联系方式 |

**反模式:**
- Agent代码中使用`typer.confirm()`
- 人类联系硬编码在特定图节点
- Agent无法提出澄清问题
- 仅支持单一响应格式(仅是/否)

---

Factor 8: Own Your Control Flow

要素8:自主管理控制流

Principle: Custom control flow, not framework defaults. Full control over routing, retries, compaction.
Search Patterns:
bash
undefined
原则: 自定义控制流,而非框架默认值。完全控制路由、重试、压缩。
搜索模式:
bash
undefined

Look for routing logic

查找路由逻辑

grep -r "add_conditional_edges|route_|should_continue" --include="*.py"
grep -r "add_conditional_edges|route_|should_continue" --include="*.py"

Look for custom loops

查找自定义循环

grep -r "while True|for.*in.range" --include=".py" | grep -v test
grep -r "while True|for.*in.range" --include=".py" | grep -v test

Look for execution mode control

查找执行模式控制

grep -r "execution_mode|agentic|structured" --include="*.py"

**File Patterns:** `**/orchestrator/*.py`, `**/graph/*.py`, `**/core/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Custom routing functions, conditional edges, execution mode control |
| **Partial** | Framework control flow with some customization |
| **Weak** | Default framework loop with no custom routing |

**Anti-patterns:**
- Single path through graph with no branching
- No distinction between tool types (all treated same)
- Framework-default error handling only
- No rate limiting or resource management

---
grep -r "execution_mode|agentic|structured" --include="*.py"

**文件模式:** `**/orchestrator/*.py`, `**/graph/*.py`, `**/core/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 自定义路由函数、条件边、执行模式控制 |
| **部分合规** | 框架控制流,具备一定自定义能力 |
| **弱合规** | 默认框架循环,无自定义路由 |

**反模式:**
- 图中仅存在单一路径,无分支
- 不区分工具类型(所有工具同等处理)
- 仅使用框架默认错误处理
- 无速率限制或资源管理

---

Factor 9: Compact Errors into Context

要素9:将错误压缩到上下文中

Principle: Errors in context enable self-healing. Track consecutive errors, escalate after threshold.
Search Patterns:
bash
undefined
原则: 上下文中的错误支持自我修复。跟踪连续错误,达到阈值后升级。
搜索模式:
bash
undefined

Look for error handling

查找错误处理

grep -r "except.Exception|error_history|consecutive_errors" --include=".py"
grep -r "except.Exception|error_history|consecutive_errors" --include=".py"

Look for retry logic

查找重试逻辑

grep -r "retry|backoff|max_attempts" --include="*.py"
grep -r "retry|backoff|max_attempts" --include="*.py"

Look for escalation

查找升级机制

grep -r "escalate|human_escalation" --include="*.py"

**File Patterns:** `**/agents/*.py`, `**/orchestrator/*.py`, `**/core/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Errors in context, retry with threshold, automatic escalation |
| **Partial** | Errors logged and returned, no automatic retry loop |
| **Weak** | Errors logged only, not fed back to LLM, task fails immediately |

**Anti-patterns:**
- `logger.error()` without adding to context
- No retry mechanism (fail immediately)
- No consecutive error tracking
- No escalation to humans after repeated failures

---
grep -r "escalate|human_escalation" --include="*.py"

**文件模式:** `**/agents/*.py`, `**/orchestrator/*.py`, `**/core/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 错误纳入上下文,带阈值的重试,自动升级 |
| **部分合规** | 错误已记录并返回,无自动重试循环 |
| **弱合规** | 仅记录错误,未反馈给LLM,任务立即失败 |

**反模式:**
- `logger.error()`但未添加到上下文
- 无重试机制(立即失败)
- 无连续错误跟踪
- 重复失败后无人工升级机制

---

Factor 10: Small, Focused Agents

要素10:小型、聚焦的Agent

Principle: Each agent has narrow responsibility, 3-10 steps max.
Search Patterns:
bash
undefined
原则: 每个Agent职责单一,最多3-10个步骤。
搜索模式:
bash
undefined

Look for agent classes

查找Agent类

grep -r "class.*Agent|class.*Architect|class.Developer" --include=".py"
grep -r "class.*Agent|class.*Architect|class.Developer" --include=".py"

Look for step definitions

查找步骤定义

grep -r "steps|tasks" --include="*.py" | head -20
grep -r "steps|tasks" --include="*.py" | head -20

Count methods per agent

统计每个Agent的方法数

grep -r "async def|def " agents/*.py 2>/dev/null | wc -l

**File Patterns:** `**/agents/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | 3+ specialized agents, each with single responsibility, step limits |
| **Partial** | Multiple agents but some have broad scope |
| **Weak** | Single "god" agent that handles everything |

**Anti-patterns:**
- Single agent with 20+ tools
- Agent with unbounded step count
- Mixed responsibilities (planning + execution + review)
- No step or time limits on agent execution

---
grep -r "async def|def " agents/*.py 2>/dev/null | wc -l

**文件模式:** `**/agents/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 3个以上专用Agent,每个职责单一,有步骤限制 |
| **部分合规** | 多个Agent,但部分Agent范围较广 |
| **弱合规** | 单一“全能”Agent处理所有事务 |

**反模式:**
- 单一Agent包含20+工具
- Agent无步骤数量限制
- 混合职责(规划+执行+审查)
- Agent执行无步骤或时间限制

---

Factor 11: Trigger from Anywhere

要素11:从任意位置触发

Principle: Workflows triggerable from CLI, REST, WebSocket, Slack, webhooks, etc.
Search Patterns:
bash
undefined
原则: 工作流可从CLI、REST、WebSocket、Slack、Webhook等触发。
搜索模式:
bash
undefined

Look for entry points

查找入口点

grep -r "@cli.command|@router.post|@app.post" --include="*.py"
grep -r "@cli.command|@router.post|@app.post" --include="*.py"

Look for WebSocket support

查找WebSocket支持

grep -r "WebSocket|websocket" --include="*.py"
grep -r "WebSocket|websocket" --include="*.py"

Look for external integrations

查找外部集成

grep -r "slack|discord|webhook" --include="*.py" -i

**File Patterns:** `**/routes/*.py`, `**/cli/*.py`, `**/main.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | CLI + REST + WebSocket + webhooks + chat integrations |
| **Partial** | CLI + REST API available |
| **Weak** | CLI only, no programmatic access |

**Anti-patterns:**
- Only `if __name__ == "__main__"` entry point
- No REST API for external systems
- No event streaming for real-time updates
- Trigger logic tightly coupled to execution

---
grep -r "slack|discord|webhook" --include="*.py" -i

**文件模式:** `**/routes/*.py`, `**/cli/*.py`, `**/main.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | CLI + REST + WebSocket + Webhook + 聊天集成 |
| **部分合规** | 支持CLI + REST API |
| **弱合规** | 仅支持CLI,无程序化访问方式 |

**反模式:**
- 仅存在`if __name__ == "__main__"`入口点
- 无供外部系统调用的REST API
- 无实时更新的事件流
- 触发逻辑与执行紧密耦合

---

Factor 12: Stateless Reducer

要素12:无状态归约器

Principle: Agents as pure functions: (state, input) -> (state, output). No side effects in agent logic.
Search Patterns:
bash
undefined
原则: Agent作为纯函数:(state, input) -> (state, output)。Agent逻辑中无副作用。
搜索模式:
bash
undefined

Look for state mutation patterns

查找状态突变模式

grep -r ".status = |.field = " --include="*.py"
grep -r ".status = |.field = " --include="*.py"

Look for immutable updates

查找不可变更新

grep -r "model_copy|.copy(|with_" --include="*.py"
grep -r "model_copy|.copy(|with_" --include="*.py"

Look for side effects in agents

查找Agent中的副作用

grep -r "write_file|subprocess|requests." agents/*.py 2>/dev/null

**File Patterns:** `**/agents/*.py`, `**/nodes/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Immutable state updates, side effects isolated to tools/handlers |
| **Partial** | Mostly immutable, some in-place mutations |
| **Weak** | State mutated in place, side effects mixed with agent logic |

**Anti-patterns:**
- `state.field = new_value` (mutation)
- File writes inside agent methods
- HTTP calls inside agent decision logic
- Shared mutable state between agents

---
grep -r "write_file|subprocess|requests." agents/*.py 2>/dev/null

**文件模式:** `**/agents/*.py`, `**/nodes/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 不可变状态更新,副作用隔离到工具/处理器 |
| **部分合规** | 大部分不可变,存在少量原地突变 |
| **弱合规** | 状态原地突变,副作用与Agent逻辑混合 |

**反模式:**
- `state.field = new_value`(突变)
- Agent方法中写入文件
- Agent决策逻辑中包含HTTP调用
- Agent之间共享可变状态

---

Factor 13: Pre-fetch Context

要素13:预获取上下文

Principle: Fetch likely-needed data upfront rather than mid-workflow.
Search Patterns:
bash
undefined
原则: 预先获取可能需要的数据,而非在工作流中获取。
搜索模式:
bash
undefined

Look for context pre-fetching

查找上下文预获取

grep -r "pre_fetch|prefetch|fetch_context" --include="*.py"
grep -r "pre_fetch|prefetch|fetch_context" --include="*.py"

Look for RAG/embedding systems

查找RAG/嵌入系统

grep -r "embedding|vector|semantic_search" --include="*.py"
grep -r "embedding|vector|semantic_search" --include="*.py"

Look for related file discovery

查找相关文件发现

grep -r "related_tests|similar_|find_relevant" --include="*.py"

**File Patterns:** `**/context/*.py`, `**/retrieval/*.py`, `**/rag/*.py`

**Compliance Criteria:**

| Level | Criteria |
|-------|----------|
| **Strong** | Automatic pre-fetch of related tests, files, docs before planning |
| **Partial** | Manual context passing, design doc support |
| **Weak** | No pre-fetching, LLM must request all context via tools |

**Anti-patterns:**
- Architect starts with issue only, no codebase context
- No semantic search for similar past work
- Related tests/files discovered only during execution
- No RAG or document retrieval system

---
grep -r "related_tests|similar_|find_relevant" --include="*.py"

**文件模式:** `**/context/*.py`, `**/retrieval/*.py`, `**/rag/*.py`

**合规性标准:**

| 级别 | 标准 |
|-------|----------|
| **强合规** | 规划前自动预获取相关测试、文件、文档 |
| **部分合规** | 手动传递上下文,支持设计文档 |
| **弱合规** | 无预获取,LLM必须通过工具请求所有上下文 |

**反模式:**
| 级别 | 标准 |
|-------|----------|
| **强合规** | 规划前自动预获取相关测试、文件、文档 |
| **部分合规** | 手动传递上下文,支持设计文档 |
| **弱合规** | 无预获取,LLM必须通过工具请求所有上下文 |

**反模式:**
- 架构师仅从问题开始,无代码库上下文
- 无相似过往工作的语义搜索
- 相关测试/文件仅在执行过程中发现
- 无RAG或文档检索系统

---

Output Format

输出格式

Executive Summary Table

执行摘要表

markdown
| Factor | Status | Notes |
|--------|--------|-------|
| 1. Natural Language -> Tool Calls | **Strong/Partial/Weak** | [Key finding] |
| 2. Own Your Prompts | **Strong/Partial/Weak** | [Key finding] |
| ... | ... | ... |
| 13. Pre-fetch Context | **Strong/Partial/Weak** | [Key finding] |

**Overall**: X Strong, Y Partial, Z Weak
markdown
| 要素 | 状态 | 说明 |
|--------|--------|-------|
| 1. 自然语言 -> 工具调用 | **强合规/部分合规/弱合规** | [关键发现] |
| 2. 自主管理提示词 | **强合规/部分合规/弱合规** | [关键发现] |
| ... | ... | ... |
| 13. 预获取上下文 | **强合规/部分合规/弱合规** | [关键发现] |

**总体:** X个强合规,Y个部分合规,Z个弱合规

Per-Factor Analysis

分要素分析

For each factor, provide:
  1. Current Implementation
    • Evidence with file:line references
    • Code snippets showing patterns
  2. Compliance Level
    • Strong/Partial/Weak with justification
  3. Gaps
    • What's missing vs. 12-Factor ideal
  4. Recommendations
    • Actionable improvements with code examples

针对每个要素,提供:
  1. 当前实现
    • 带文件:行号引用的证据
    • 展示模式的代码片段
  2. 合规级别
    • 强合规/部分合规/弱合规及理由
  3. 差距
    • 与12-Factor理想状态的缺失部分
  4. 建议
    • 可落地的改进方案及代码示例

Analysis Workflow

分析工作流

  1. Initial Scan
    • Run search patterns for all factors
    • Identify key files for each factor
    • Note any existing compliance documentation
  2. Deep Dive (per factor)
    • Read identified files
    • Evaluate against compliance criteria
    • Document evidence with file paths
  3. Gap Analysis
    • Compare current vs. 12-Factor ideal
    • Identify anti-patterns present
    • Prioritize by impact
  4. Recommendations
    • Provide actionable improvements
    • Include before/after code examples
    • Reference roadmap if exists
  5. Summary
    • Compile executive summary table
    • Highlight strengths and critical gaps
    • Suggest priority order for improvements

  1. 初始扫描
    • 针对所有要素运行搜索模式
    • 识别每个要素的关键文件
    • 记录现有合规文档
  2. 深度分析(按要素)
    • 阅读识别出的文件
    • 对照合规标准评估
    • 记录带文件路径的证据
  3. 差距分析
    • 对比当前实现与12-Factor理想状态
    • 识别存在的反模式
    • 按影响优先级排序
  4. 建议
    • 提供可落地的改进方案
    • 包含改进前后的代码示例
    • 参考现有路线图(若有)
  5. 总结
    • 编译执行摘要表
    • 突出优势和关键差距
    • 建议改进的优先级顺序

Quick Reference: Compliance Scoring

快速参考:合规评分

ScoreMeaningAction
StrongFully implements principleMaintain, minor optimizations
PartialSome implementation, significant gapsPlanned improvements
WeakMinimal or no implementationHigh priority for roadmap
评分含义行动
强合规完全实现原则维护,小幅优化
部分合规部分实现,存在显著差距计划改进
弱合规极少或未实现路线图高优先级

When to Use This Skill

何时使用该技能

  • Evaluating new LLM-powered systems
  • Reviewing agent architecture decisions
  • Auditing production agentic applications
  • Planning improvements to existing agents
  • Comparing frameworks or implementations
  • 评估新的LLM驱动系统
  • 审查Agent架构决策
  • 审计生产环境中的Agent类应用
  • 规划现有Agent的改进
  • 对比不同框架或实现