Writing Better Skills
Create better skills for agents.
A skill helps an agent do work. It is reusable operational guidance plus optional references, scripts, tests, and narrow remediation. It is not something that "turns an agent into a skill."
This skill is the control plane for authoring other skills:
- - it tells the agent when to use the skill-creation framework
- what laws must not be violated
- which references to read for each decision
- when scripts, tests, and self-healing are justified
- what completion means
When to Use
Use this when authoring or revising a skill and you need to decide:
- - what belongs in INLINECODE0
- what should move into INLINECODE1
- when project-local context is needed
- when to add scripts and tests
- whether self-healing is justified
- whether a fresh agent could use the skill without guessing
The Iron Laws
CODEBLOCK0
If a path, command, constraint, or convention belongs to one repository, it goes in project.skill.md, not in the reusable skill.
CODEBLOCK1
If another agent would have to invent project-local commands, output paths, trigger conditions, or completion criteria, the skill is incomplete.
Violating the letter of these laws is violating the spirit of the skill.
Project-Local Context Comes First
The global skill must stay reusable.
Before doing substantial work with a skill in a repository:
- 1. Look for
project.skill.md in the project root. - If it exists, read it before taking action.
- If it does not exist and local context is needed, create it from
project.skill.template.md. - Put environment-specific paths, commands, constraints, and conventions in
project.skill.md, not in the global skill. - Treat
project.skill.md as overriding generic guidance in SKILL.md when local details differ.
Read references/project-skill-context.md before defining or revising that contract.
Skill Organization Model
SKILL.md = the router
SKILL.md is the main behavioral document. It should tell the agent:
- - when to use the skill
- what laws and stop conditions apply
- what order to follow
- which references to read
- which scripts to run
- what completion requires
references/ = deep guidance
References hold heavier, conditional, or decision-specific material.
Use references for:
- - description-writing rules
- project-local context rules
- architecture-level decisions
- script/test conventions
- self-healing rules
- behavioral validation
- completion gates
scripts/ = deterministic helpers
Use scripts for repeated deterministic work the agent should not keep re-deriving.
tests/ = proof
Use tests to prove shipped scripts or promised behaviors work.
self-healing/ = narrow remediation
Use self-healing only for safe, local, repeatable fixes.
Architecture Levels
Choose the smallest structure that reliably supports the work.
Minimal skill
CODEBLOCK2
Reference-backed skill
CODEBLOCK3
Operational skill
CODEBLOCK4
Resilient operational skill
CODEBLOCK5
Read references/skill-architecture-levels.md before deciding how much structure to add.
Authoring Phases
You must complete each phase before moving on.
Phase 1: Define the boundary
Decide:
- - what problem the skill solves
- what belongs in the reusable global skill
- what must remain project-local
- whether local context actually matters
If local commands, paths, outputs, or constraints vary by project, plan for project.skill.template.md.
Phase 2: Define trigger and routing
Write the frontmatter and top of
SKILL.md.
Requirements:
- - description says when to use the skill
- INLINECODE18 routes the agent to
project.skill.md early when local context matters - INLINECODE20 tells the agent which references/scripts matter at which step
Read references/description-writing.md before finalizing the description.
Phase 3: Add only justified structure
Add references, scripts, tests, and self-healing only when earned.
Use these references:
- -
references/script-test-conventions.md before shipping scripts - INLINECODE23 before adding self-healing
- INLINECODE24 before deciding what to validate
Phase 4: Validate fresh-agent usability
Before calling the skill complete, test whether a fresh agent could:
- - identify when to use the skill
- find the right local context file
- choose the right reference or script
- know what completion means
Read references/behavioral-validation-checklist.md.
Phase 5: Apply the completion gate
Do not claim the skill is complete until it passes the completion gate.
Read references/completion-gate.md.
Routing Map
Use this map while authoring:
- - Need to define project-local context? → INLINECODE27
- Need to choose architecture level? → INLINECODE28
- Need to write a better trigger description? → INLINECODE29
- Need to add or test scripts? → INLINECODE30
- Need to decide whether healing is allowed? → INLINECODE31
- Need to validate fresh-agent usability? → INLINECODE32
- Need to decide if the skill is complete? → INLINECODE33
- Need general workflow or output guidance? →
references/workflows.md, INLINECODE35
Scripts in This Repo
Use the shipped scripts when they reduce repeated, deterministic work:
- -
scripts/quick_validate.py — fast validation of frontmatter and core structural promises
If you find yourself manually re-checking the same structural conditions repeatedly, prefer strengthening this validator rather than rewriting the checks ad hoc.
Reference Skill
See reference-skills/release-notes-generator/ for a canonical reference skill authored using this framework.
Use it as a model implementation of:
- - a reusable global skill
- a shipped INLINECODE38
- references routed from INLINECODE39
- a deterministic script with a paired test
- narrow self-healing
It is a specimen of the framework, not a substitute for the framework.
Red Flags — STOP
Stop and correct course if you are thinking:
- - "I’ll just put this command/path in SKILL.md"
- "The agent can infer the local commands"
- "This script is too small to test"
- "I’ll add the test later"
- "This self-healing is probably safe"
- "The example will clarify the missing instructions"
- "A fresh agent will figure it out"
- "Close enough"
All of these usually mean you are about to violate one of the iron laws.
Common Rationalizations
| Excuse | Reality |
|---|
| "It’s faster to put the path in SKILL.md" | That contaminates the global skill with local assumptions. Use project.skill.md. |
| "Agents can infer the local commands" |
Guessing local commands is exactly what project-local context is for. |
| "This script is simple, it doesn’t need a test" | If it is worth shipping, it is usually worth validating. |
| "Self-healing can just fix a bunch of stuff" | Broad auto-fixes are risk, not resilience. |
| "The worked example will show the pattern" | The skill itself must be usable without depending on an example. |
| "The structure looks right, so the skill is done" | Organization alone does not prove fresh-agent usability. |
Completion Gate
Before claiming a skill is complete, verify all of these:
- - the description says when to use the skill
- the global skill contains no project-specific commands, paths, or constraints
- INLINECODE41 routes the agent to
project.skill.md early when local context matters - references are clearly named and linked from INLINECODE43
- shipped scripts are justified and paired with tests, or explicitly exempted with a reason
- self-healing is narrow and safe
- a fresh agent could use the skill without guessing critical facts
Bottom Line
A better skill is not just more elaborate.
A better skill:
- - stays reusable at the global level
- pushes local facts into INLINECODE44
- routes the agent clearly through references and scripts
- validates what it ships
- resists rationalization
- is complete only when a fresh agent could use it without guessing
编写更优技能
为智能体创建更优技能。
技能帮助智能体完成工作。它是可复用的操作指南,外加可选的参考资料、脚本、测试和精准修复。它不是那种将智能体变成技能的东西。
本技能是编写其他技能的控制平面:
- - 它告诉智能体何时使用技能创建框架
- 哪些法则不得违反
- 每个决策应阅读哪些参考资料
- 何时使用脚本、测试和自愈功能
- 完成意味着什么
何时使用
在编写或修订技能时使用本技能,你需要决定:
- - 哪些内容应放入 SKILL.md
- 哪些内容应移至 references/
- 何时需要项目本地上下文
- 何时添加脚本和测试
- 自愈功能是否合理
- 新智能体能否无需猜测即可使用该技能
铁律
text
全局技能中不得包含项目特定上下文
如果某个路径、命令、约束或约定属于某个仓库,则应放入 project.skill.md,而非可复用技能中。
text
技能只有在全新智能体无需猜测关键事实即可使用时才算完成
如果其他智能体需要自行编造项目本地命令、输出路径、触发条件或完成标准,则该技能不完整。
违反这些法则的字面含义就是违反本技能的精神。
项目本地上下文优先
全局技能必须保持可复用性。
在仓库中使用技能进行实质性工作之前:
- 1. 在项目根目录查找 project.skill.md。
- 如果存在,在采取行动前先阅读它。
- 如果不存在且需要本地上下文,则从 project.skill.template.md 创建它。
- 将环境特定的路径、命令、约束和约定放入 project.skill.md,而非全局技能中。
- 当本地细节与 SKILL.md 中的通用指南不同时,以 project.skill.md 为准。
在定义或修订该契约前,请阅读 references/project-skill-context.md。
技能组织模型
SKILL.md = 路由器
SKILL.md 是主要行为文档。它应告诉智能体:
- - 何时使用该技能
- 适用哪些法则和停止条件
- 遵循什么顺序
- 阅读哪些参考资料
- 运行哪些脚本
- 完成需要什么条件
references/ = 深度指南
参考资料包含更重、有条件或特定于决策的材料。
参考资料用于:
- - 描述编写规则
- 项目本地上下文规则
- 架构级决策
- 脚本/测试约定
- 自愈规则
- 行为验证
- 完成关卡
scripts/ = 确定性辅助工具
脚本用于重复的确定性工作,智能体不应反复重新推导。
tests/ = 证明
测试用于证明已交付的脚本或承诺的行为有效。
self-healing/ = 精准修复
自愈仅用于安全、本地、可重复的修复。
架构层级
选择能够可靠支持工作的最小结构。
最小技能
text
my-skill/
└── SKILL.md
带参考资料的技能
text
my-skill/
├── SKILL.md
├── project.skill.template.md
└── references/
可操作技能
text
my-skill/
├── SKILL.md
├── project.skill.template.md
├── references/
├── scripts/
└── tests/
弹性可操作技能
text
my-skill/
├── SKILL.md
├── project.skill.template.md
├── references/
├── scripts/
├── tests/
└── self-healing/
在决定添加多少结构之前,请阅读 references/skill-architecture-levels.md。
编写阶段
每个阶段完成后才能进入下一阶段。
阶段 1:定义边界
决定:
- - 技能解决什么问题
- 哪些内容属于可复用的全局技能
- 哪些内容必须保持项目本地化
- 本地上下文是否确实重要
如果本地命令、路径、输出或约束因项目而异,则规划使用 project.skill.template.md。
阶段 2:定义触发和路由
编写 SKILL.md 的前言和顶部内容。
要求:
- - 描述说明何时使用该技能
- 当本地上下文重要时,SKILL.md 尽早将智能体路由到 project.skill.md
- SKILL.md 告诉智能体在哪个步骤使用哪些参考资料/脚本
在最终确定描述之前,请阅读 references/description-writing.md。
阶段 3:仅添加合理的结构
仅在必要时添加参考资料、脚本、测试和自愈功能。
使用以下参考资料:
- - 交付脚本前使用 references/script-test-conventions.md
- 添加自愈功能前使用 references/self-healing-rules.md
- 决定验证内容前使用 references/skill-testing.md
阶段 4:验证新智能体可用性
在宣布技能完成之前,测试新智能体能否:
- - 识别何时使用该技能
- 找到正确的本地上下文文件
- 选择正确的参考资料或脚本
- 知道完成意味着什么
阅读 references/behavioral-validation-checklist.md。
阶段 5:应用完成关卡
在通过完成关卡之前,不要声称技能已完成。
阅读 references/completion-gate.md。
路由图
编写时使用此图:
- - 需要定义项目本地上下文?→ references/project-skill-context.md
- 需要选择架构层级?→ references/skill-architecture-levels.md
- 需要编写更好的触发描述?→ references/description-writing.md
- 需要添加或测试脚本?→ references/script-test-conventions.md
- 需要决定是否允许自愈?→ references/self-healing-rules.md
- 需要验证新智能体可用性?→ references/behavioral-validation-checklist.md
- 需要决定技能是否完成?→ references/completion-gate.md
- 需要通用工作流或输出指南?→ references/workflows.md、references/output-patterns.md
本仓库中的脚本
当已交付的脚本能减少重复的确定性工作时使用它们:
- - scripts/quick_validate.py — 快速验证前言和核心结构承诺
如果你发现自己反复手动检查相同的结构条件,建议加强此验证器,而非临时重写检查逻辑。
参考技能
参见 reference-skills/release-notes-generator/,这是一个使用本框架编写的规范参考技能。
将其作为以下内容的模型实现:
- - 可复用的全局技能
- 已交付的 project.skill.template.md
- 从 SKILL.md 路由的参考资料
- 带有配对测试的确定性脚本
- 精准自愈
它是本框架的样本,而非框架的替代品。
红旗警示 — 立即停止
如果你有以下想法,请立即停止并纠正方向:
- - 我就把这个命令/路径放在 SKILL.md 里
- 智能体可以推断出本地命令
- 这个脚本太小了,不需要测试
- 我稍后再添加测试
- 这个自愈功能可能安全
- 示例会澄清缺失的指令
- 新智能体会自己搞明白
- 差不多就行了
所有这些通常意味着你即将违反某条铁律。
常见合理化借口
| 借口 | 现实 |
|---|
| 把路径放在 SKILL.md 里更快 | 这用本地假设污染了全局技能。请使用 project.skill.md。 |
| 智能体可以推断出本地命令 |
猜测本地命令正是项目本地上下文的用途。 |
| 这个脚本很简单,不需要测试 | 如果值得交付,通常也值得验证。 |
| 自愈功能可以修复一堆东西 | 广泛的自动修复是风险,而非弹性。 |
| 工作示例会展示模式 | 技能本身必须可用,不依赖示例。 |
| 结构看起来没问题,所以技能完成了 | 仅靠组织并不能证明新智能体可用性。 |
完成关卡
在声称技能完成之前,验证以下所有内容:
- - 描述说明了何时使用该技能
- 全局技能不包含项目特定的命令、路径或约束
- 当本地上下文重要时,SKILL.md 尽早将智能体路由到 project.skill.md
- 参考资料命名清晰,并从 SKILL.md 链接
- 已交付的脚本合理且与测试配对,或明确说明豁免理由
- 自愈功能精准且安全
- 新智能体无需猜测关键事实即可使用该技能
核心要点
更优的技能不仅仅是更复杂。
更优的技能:
- - 在全局层面保持可复用性
- 将本地事实推入 project.skill.md
- 通过参考资料和脚本清晰路由智能体
- 验证其交付的内容
- 抵制合理化借口
- 仅在新智能体无需猜测即可使用时才算完成