什么值得买App下载 App ›
连续签到专享现金活动

谷歌提出5种Skill的设计模式,Skill的高阶编写技巧

虽然目前 Claude Code、Gemini CLI、Cursor 等超过 30 个 Agent 工具已统一了 SKILL.md 的布局格式,解决了规范问题,但实际应用中,不同 Agent 的表现差异依然巨大。这种差异并非源于格式本身,而是取决于内部内容的设计逻辑。Google Cloud Tech 提出了 5 种经过实战验证的 Skill 设计模式,旨在解决 Agent 在任务执行中常见的逻辑松散、输出不稳定等问题,帮助开发者从“会用格式”进阶到“设计得好”。
01模式一:Tool Wrapper(工具包装器)
Tool Wrapper 模式旨在解决系统提示词臃肿的问题。其核心理念是将特定库的最佳实践或团队编码规范封装成独立的 Skill,供 Agent 按需加载。这种设计不仅能保持系统提示词的精简,节省 Token,还能实现团队规范的“即插即用”。
实现要点:在 references/ 目录下存放详细的规范文档;在 SKILL.md 中明确指示 Agent“何时加载”以及“加载后如何使用”。以下是一个 FastAPI 开发专家 Skill 的示例:
# skills/api-expert/SKILL.md
---
name: api-expert
description: FastAPI development best practices and conventions. Use when building, reviewing, or debugging FastAPI applications.
---
You are an expert in FastAPI development.

## Core Conventions
Load 'references/conventions.md' for the complete list of best practices.

## When Reviewing Code
1. Load the conventions reference
2. Check code against each convention
3. For violations, cite the 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
02模式二:Generator(模板驱动生成)
Generator 模式针对 Agent 输出结构不稳定的问题,采用“内容”与“结构”分离的策略。通过 assets/ 目录存放输出模板,references/ 目录存放风格指南,让 SKILL.md 充当“项目经理”,指挥 Agent 按步骤填充模板。这种模式复用性极强,只需更换模板即可产出不同类型的文档。
# skills/report-generator/SKILL.md
---
name: report-generator
description: Generates structured technical reports in 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 structure.
Step 3: Ask the user for missing information:
- Topic or subject
- Key findings or data points
- Target audience
Step 4: Fill the template following the style guide.
Step 5: Return the completed report.
03模式三:Reviewer(模块化检查清单)
Reviewer 模式将“查什么”与“怎么查”分离,避免在系统提示词中堆砌冗长的检查规则。通过将规则外部化到 references/review-checklist.md,Agent 可以动态加载不同的检查标准(如 Python 风格指南或 OWASP 安全清单),从而在不改变基础设施的情况下灵活切换审查角色。
# skills/code-reviewer/SKILL.md
---
name: code-reviewer
description: Reviews Python code for quality, style, and bugs.
---
You are a Python code reviewer. Follow this protocol exactly:

Step 1: Load 'references/review-checklist.md' for review criteria.
Step 2: Read the user's code carefully.
Step 3: Apply each rule. For every violation:
- Note the line number
- Classify severity: error / warning / info
- Explain WHY it's a problem
- Suggest a specific fix

Step 4: Produce structured output:
- **Summary**: What the code does, overall assessment
- **Findings**: Grouped by severity
- **Score**: Rate 1-10 with justification
- **Top 3 Recommendations**
04模式四:Inversion(先问再做)
针对 Agent 天生爱“猜”导致复杂场景下理解偏差的问题,Inversion 模式将交互逻辑从“用户驱动 Agent”反转为“Agent 面试用户”。通过设置明确的“门禁”指令和分阶段提问机制,强制 Agent 在收集完所有必要信息前不得开始任务,从而提高需求理解的准确性。
# skills/project-planner/SKILL.md
---
name: project-planner
description: Plans software projects by gathering requirements through structured questions before producing a plan.
---
You are conducting a requirements interview.
DO NOT start building until all phases are complete.

## Phase 1 — Problem Discovery (ask one question at a time)
Ask 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?"

## Phase 2 — Technical Constraints (only after Phase 1 is complete)
- Q4: "What deployment environment will you use?"
- Q5: "Do you have technology stack preferences?"
- Q6: "What are the non-negotiable requirements?"

## Phase 3 — Synthesis (only after all questions answered)
1. Load 'assets/plan-template.md'
2. Fill in every section using gathered requirements
3. Present the plan
4. Ask: "Does this capture your requirements?"
5. Iterate until user confirms
05模式五:Pipeline(严格流水线)
Pipeline 模式适用于多步骤且不能跳步的严格任务(如 API 文档生成)。通过设置“硬检查点”,确保 Agent 必须完成当前步骤并可能获得人工确认后,才能进入下一步,从而保证流程完整性和最终产出质量。
# skills/doc-pipeline/SKILL.md
---
name: doc-pipeline
description: Generates API documentation from Python source code.
---
You are running a documentation pipeline.
Execute each step in order. Do NOT skip steps.

## Step 1 — Parse & Inventory
Analyze the code to extract all public classes and functions.
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 format
- Generate docstrings following the style guide
- Present each for user approval

**Do NOT proceed to Step 3 until user confirms.**

## Step 3 — Assemble Documentation
Load 'assets/api-doc-template.md' for output structure.
Compile all symbols into a single API reference document.

## Step 4 — Quality Check
Review against 'references/quality-checklist.md':
- Every public symbol documented
- Every parameter has type and description
- At least one usage example per function
Report results. Fix issues before final delivery.
06模式选择与组合应用

场景适用性分析

单一模式适用场景

根据具体需求选择最匹配的基础模式

  • Tool Wrapper:仅需让 Agent 掌握特定库或规范时使用。
  • Generator:需要输出固定格式文档或结构化内容时使用。
  • Reviewer:需要进行代码检查、评审或合规性审计时使用。
  • Inversion:需求复杂、易产生歧义,需明确澄清时使用。
  • Pipeline:任务包含多个严格步骤,严禁跳步时使用。
组合策略建议

应对复杂生产环境的混合模式

  • Pipeline + Reviewer:在流水线末端增加审查步骤,实现自我质检。
  • Inversion + Generator:先通过反转模式收集信息,再利用生成器填充模板。
  • 渐进式加载:利用 ADK 机制按需加载,避免组合使用导致 Token 消耗过大。
综上所述,SKILL.md 的格式与 YAML 结构已趋于标准化,真正的竞争壁垒在于能否将业务逻辑抽象为合适的设计模式。这五种模式的本质是通过“约束”来对抗 Agent 爱猜、爱跳步的本能。在实际开发中,灵活组合 Pipeline、Reviewer 和 Tool Wrapper 等原子化 Skill,是构建高质量生产级 Agent 架构的关键。

评论

评论区空态插画

当前文章无评论,是时候发表评论了