
谈到 𝚂𝙺𝙸𝙻𝙻.𝚖𝚍,开发者往往会盯着格式不放——把 YAML 写对、把目录结构搭好、严格遵循规范。但如今已有 30 多个 agent 工具(比如 Claude Code、Gemini CLI 和 Cursor)在同一套布局上完成标准化,“格式问题”几乎已经过时了。
现在的挑战在于内容设计。规范解释了如何打包一个 skill,却完全没有告诉你该如何组织其中的逻辑。举例来说,一个封装 FastAPI 约定的 skill,其运作方式与一个四步文档流水线截然不同,尽管它们对外呈现的 𝚂𝙺𝙸𝙻𝙻.𝚖𝚍 文件看起来一模一样。
通过研究整个生态里 skill 的构建方式——从 Anthropic 的仓库到 Vercel,再到 Google 的内部指南——我们发现有五种反复出现的设计模式,能够帮助开发者构建 agent。
作者:@Saboo_Shubham_ 与 @lavinigam
本文将结合可运行的 ADK 代码逐一讲解:
-
Tool Wrapper:让你的 agent 瞬间精通任何库
-
Generator:用可复用模板生成结构化文档
-
Reviewer:按严重程度用清单给代码打分
-
Inversion:agent 先“访谈”你,再开始行动
-
Pipeline:用检查点强制执行严格的多步工作流
https://google.github.io/adk-docs/
Pattern 1: The Tool Wrapper
Tool Wrapper 会为你的 agent 提供某个特定库的按需上下文。你不必把 API 约定硬塞进 system prompt,而是将它们打包进一个 skill。你的 agent 只会在确实要处理该技术时才加载这段上下文。
# skills/project-planner/SKILL.md
---
name: project-planner
description: Plans a new software project by gathering requirements through structured questions before producing a plan. Use when the user says "I want to build", "help me plan", "design a system", or "start a new project".
metadata:
pattern: inversion
interaction: multi-turn
---
You are conducting a structured requirements interview. DO NOT start building or designing until all phases are complete.
## Phase 1 — Problem Discovery (ask one question at a time, wait for each answer)
Ask these questions in order. Do not skip any.
- Q1: "What problem does this project solve for its users?"
- Q2: "Who are the primary users? What is their technical level?"
- Q3: "What is the expected scale? (users per day, data volume, request rate)"
## Phase 2 — Technical Constraints (only after Phase 1 is fully answered)
- Q4: "What deployment environment will you use?"
- Q5: "Do you have any technology stack requirements or preferences?"
- Q6: "What are the non-negotiable requirements? (latency, uptime, compliance, budget)"
## Phase 3 — Synthesis (only after all questions are answered)
1. Load 'assets/plan-template.md' for the output format
2. Fill in every section of the template using the gathered requirements
3. Present the completed plan to the user
4. Ask: "Does this plan accurately capture your requirements? What would you change?"
5. Iterate on feedback until the user confirms
这是最容易实现的一种模式。𝚂𝙺𝙸𝙻𝙻.𝚖𝚍 文件会在用户提示中监听特定库的关键词,动态从 𝚛𝚎𝚏𝚎𝚛𝚎𝚗𝚌𝚎𝚜/ 目录加载你的内部文档,并将这些规则当作绝对真理来执行。这正是把团队内部编码规范或特定框架最佳实践,直接分发进开发者工作流的机制。
下面是一个 Tool Wrapper 的例子,它教会 agent 如何编写 FastAPI 代码。注意这些指令如何明确要求:只有在开始审查或编写代码时,才加载 𝚌𝚘𝚗𝚟𝚎𝚗𝚝𝚒𝚘𝚗𝚜.𝚖𝚍 文件:
# skills/report-generator/SKILL.md
---
name: report-generator
description: Generates structured technical reports in Markdown. Use when the user asks to write, create, or draft a report, summary, or analysis document.
metadata:
pattern: generator
output-format: markdown
---
You are a technical report generator. Follow these steps exactly:
Step 1: Load 'references/style-guide.md' for tone and formatting rules.
Step 2: Load 'assets/report-template.md' for the required output structure.
Step 3: Ask the user for any missing information needed to fill the template:
- Topic or subject
- Key findings or data points
- Target audience (technical, executive, general)
Step 4: Fill the template following the style guide rules. Every section in the template must be present in the output.
Step 5: Return the completed report as a single Markdown document.
Pattern 2: The Generator
如果说 Tool Wrapper 负责“应用知识”,那么 Generator 负责“强制一致的输出”。如果你苦于 agent 每次运行都生成不同的文档结构,Generator 会通过编排一个“填空式”的流程来解决这一点。
它利用两个可选目录:𝚊𝚜𝚜𝚎𝚝𝚜/ 存放输出模板,𝚛𝚎𝚏𝚎𝚛𝚎𝚗𝚌𝚎𝚜/ 存放风格指南。指令就像项目经理:告诉 agent 加载模板、阅读风格指南、向用户补齐缺失变量,并把内容填入文档。这对于生成可预测的 API 文档、统一 commit message、或为项目架构搭脚手架都非常实用。
在这个技术报告生成器示例中,skill 文件并不包含真实的版式或语法规则。它只是协调这些资产的检索,并强制 agent 按步骤执行:
Pattern 3: The Reviewer
Reviewer 模式把“检查什么”和“怎么检查”分离开来。你不需要写一段冗长的 system prompt 去罗列所有代码异味,而是把一份模块化的评审量表存放在 𝚛𝚎𝚏𝚎𝚛𝚎𝚗𝚌𝚎𝚜/𝚛𝚎𝚟𝚒𝚎𝚠-𝚌𝚑𝚎𝚌𝚔𝚕𝚒𝚜𝚝.𝚖𝚍 文件里。
当用户提交代码时,agent 会加载这份清单,按部就班地为提交内容打分,并按严重程度分组输出发现。如果你把 Python 风格检查清单替换成 OWASP 安全清单,你就能在完全相同的 skill 基础设施上,得到一份截然不同、同样专业的审计报告。这是自动化 PR 评审、或在人工介入之前捕捉漏洞的高效方式。
下面这个代码审查 skill 演示了这种分离:指令保持不变,但 agent 会动态加载外部清单中的具体评审标准,并被强制输出结构化、按严重程度分层的结果:
# skills/doc-pipeline/SKILL.md
---
name: doc-pipeline
description: Generates API documentation from Python source code through a multi-step pipeline. Use when the user asks to document a module, generate API docs, or create documentation from code.
metadata:
pattern: pipeline
steps: "4"
---
You are running a documentation generation pipeline. Execute each step in order. Do NOT skip steps or proceed if a step fails.
## Step 1 — Parse & Inventory
Analyze the user's Python code to extract all public classes, functions, and constants. Present the inventory as a checklist. Ask: "Is this the complete public API you want documented?"
## Step 2 — Generate Docstrings
For each function lacking a docstring:
- Load 'references/docstring-style.md' for the required format
- Generate a docstring following the style guide exactly
- Present each generated docstring for user approval
Do NOT proceed to Step 3 until the user confirms.
## Step 3 — Assemble Documentation
Load 'assets/api-doc-template.md' for the output structure. Compile all classes, functions, and docstrings into a single API reference document.
## Step 4 — Quality Check
Review against 'references/quality-checklist.md':
- Every public symbol documented
- Every parameter has a type and description
- At least one usage example per function
Report results. Fix issues before presenting the final document.
Pattern 4: Inversion
agent 天生倾向于立刻猜测并开始生成。Inversion 模式反转了这种动态:不再由用户驱动提示、agent 执行;而是由 agent 扮演访谈者的角色。
# skills/code-reviewer/SKILL.md
---
name: code-reviewer
description: Reviews Python code for quality, style, and common bugs. Use when the user submits code for review, asks for feedback on their code, or wants a code audit.
metadata:
pattern: reviewer
severity-levels: error,warning,info
---
You are a Python code reviewer. Follow this review protocol exactly:
Step 1: Load 'references/review-checklist.md' for the complete review criteria.
Step 2: Read the user's code carefully. Understand its purpose before critiquing.
Step 3: Apply each rule from the checklist to the code. For every violation found:
- Note the line number (or approximate location)
- Classify severity: error (must fix), warning (should fix), info (consider)
- Explain WHY it's a problem, not just WHAT is wrong
- Suggest a specific fix with corrected code
Step 4: Produce a structured review with these sections:
- **Summary**: What the code does, overall quality assessment
- **Findings**: Grouped by severity (errors first, then warnings, then info)
- **Score**: Rate 1-10 with brief justification
- **Top 3 Recommendations**: The most impactful improvements
Inversion 依赖明确、不可协商的“关卡”指令(例如“在所有阶段完成之前,不要开始构建”),来强制 agent 先收集上下文。它会按顺序提出结构化问题,并等待你的回答后才进入下一阶段。在对你的需求与部署约束形成完整理解之前,agent 会拒绝综合出最终产物。
想看它如何工作,请看这个项目规划 skill。这里的关键,是严格分阶段,以及那条明确的“守门”提示:在收集到所有用户答案之前,阻止 agent 综合出最终计划:
Pattern 5: The Pipeline
面对复杂任务,你承受不起跳步或忽视指令的代价。Pipeline 模式用严格的顺序工作流与硬检查点来强制执行。
指令本身就是工作流定义。通过实现明确的关卡条件(例如:从生成 docstring 进入最终组装之前必须获得用户批准),Pipeline 能确保 agent 无法绕过复杂任务,直接给出未经验证的最终结果。
这种模式会用到所有可选目录:只在需要的具体步骤里引入对应的参考文件与模板,从而让上下文窗口保持干净。
在这个文档流水线示例里,注意那些明确的关卡条件:在用户确认上一步生成的 docstring 之前,agent 被明确禁止进入组装阶段:
# skills/api-expert/SKILL.md
---
name: api-expert
description: FastAPI development best practices and conventions. Use when building, reviewing, or debugging FastAPI applications, REST APIs, or Pydantic models.
metadata:
pattern: tool-wrapper
domain: fastapi
---
You are an expert in FastAPI development. Apply these conventions to the user's code or question.
## Core Conventions
Load 'references/conventions.md' for the complete list of FastAPI best practices.
## When Reviewing Code
1. Load the conventions reference
2. Check the user's code against each convention
3. For each violation, cite the specific rule and suggest the fix
## When Writing Code
1. Load the conventions reference
2. Follow every convention exactly
3. Add type annotations to all function signatures
4. Use Annotated style for dependency injection
Choosing the right agent skill pattern
每种模式都在回答一个不同的问题。用这棵决策树为你的 use-case 找到合适的那一种:
And finally, patterns compose
这些模式并非互斥,它们可以组合。
一个 Pipeline skill 可以在最后加入 Reviewer 步骤来复核自身工作;一个 Generator 可以在最开始借助 Inversion 先收集填模板所需的变量。得益于 ADK 的 𝚂𝚔𝚒𝚕𝚕𝚃𝚘𝚘𝚕𝚜𝚎𝚝 与渐进式披露,你的 agent 只会在运行时为它确实需要的模式消耗上下文 token。
别再试图把复杂而脆弱的指令塞进一条 system prompt。把工作流拆开,应用正确的结构模式,构建可靠的 agent。
Get started today
Agent Skills 规范是开源的,并在 ADK 中获得原生支持。你已经知道如何打包格式;现在,你也知道如何设计内容了。用 Google Agent Development Kit 去构建更聪明的 agent 吧。






