Skill 寫法圖鑑

writing-for-agents

Matt Pocock | 寫作與文件 | 原文 | MIT

寫給 agent 看的文件,講 context 指標和修剪

中文翻譯

---
name: writing-for-agents
description: 撰寫給 agent 讀的文件。當建立或編輯 skill,或修改 AGENTS.md 或 CLAUDE.md 時使用。
---

這是撰寫任何由 agent 讀取的文件的參考:skill、`AGENTS.md` / `CLAUDE.md`、透過指標找到的文件。包裝方式不同;寫法沒有不同:同樣的槓桿讓每一種都變得可預測,因為 agent 每次執行走的是同樣的_流程_,而不是產出同樣的輸出。

如果你正在寫的文件是 skill,讀 [`SKILL-MECHANICS.md`](SKILL-MECHANICS.md),了解 frontmatter、呼叫方式的選擇和 router skill。

## Context 指標

**context 指標(context pointer)** 是放在 agent 的 context 裡的一個參照,它指名某份在 context 之外的素材,並且編碼了抵達它的條件。skill 的 description 就是一個;`AGENTS.md` 裡一行指名某份文件的文字,是同一種東西。指標的_措辭_,不是它的目標,決定了 agent 什麼時候會去拿那份素材,以及有多可靠。一個必備的目標掛在措辭薄弱的指標後面,是變異性的 bug:先把措辭磨利,只有磨利失敗時,才把素材 inline 進來。

指標做兩件事:說明那份素材是什麼,並列出應該觸發去拿它的**分支**(分支是文件處理的一種不同情況,所以不同次的執行會在裡面走不同的路徑)。永遠載入的指標,每一個字每一輪都要付成本,所以它比本文更值得下重手修剪:

- **把主導詞放在最前面**:指標就是它發揮觸發作用的地方。
- **每個分支一個觸發詞。** 只是替同一個分支換個說法的同義詞,就是同一個分支寫了兩次;把它們合併,只留下真正不同的分支。
- **砍掉本文已經帶有的身分資訊。**

## 兩種負載

你加的每份文件和每個指標,都會花掉兩種預算的其中一種:

- **Context 負載**是永遠載入的素材對 agent 的 window 造成的成本:`AGENTS.md` 的一行、skill 的 description、每一輪都待在 context 裡的任何東西,不管有沒有被觸發,都在花 token 和注意力。
- **認知負載**是對人類造成的成本:有哪些文件存在、什麼時候該去拿哪一份。人類就是索引。這不是要最小化的成本:它是人類自主權的代價;花在人類判斷重要的地方,在不重要的地方就拿掉。

只透過指標才拿得到的素材,付出指標自己那一行的代價,就逃過了 context 負載;完全沒有指標的素材,則完全靠認知負載撐著。

## 資訊階層

文件由兩種內容類型構成:**步驟**(agent 執行的有序動作)和**參考**(隨需查閱的定義、規則、事實)。兩者可以自由混合:全是步驟(食譜)、全是參考(review 的規則、這個 skill),或兩者都有。核心決策是每一塊內容在**資訊階層**上的位置,這是一個依 agent 多快需要這份素材來排名的階梯:

1. **檔案內的步驟**是主要層級:agent 依序要做的事。
2. **檔案內的參考**是隨需查閱的。通常是正當的扁平同儕集合(review 的每條規則都在同一階),這是好的安排,不是壞味道。
3. **揭露式參考(Disclosed reference)** 被推到獨立的檔案,透過 context 指標抵達,只有在指標被觸發時才載入。範圍涵蓋從同資料夾的兄弟檔案,一路到存在任何地方、任何文件都能指向的完全外部參考。

往下推得太少,頂層就會膨脹;推得太多,你就把 agent 真正需要的素材藏起來了。這個張力就是整個決策。

**漸進式揭露(Progressive disclosure)** 是沿著階梯往下移動(移出主檔案、放到指標後面),讓頂層保持清楚易讀。主要不是 token 最佳化:它是保護這個階層的方法。分支是最乾淨的揭露測試:每個分支都需要的就 inline,只有部分分支會碰到的就推到指標後面。當文件有步驟時,應該被揭露卻留在檔案內的參考會把步驟埋掉,讓 agent 注意不注意到它們變成擲硬幣:這是變異性的槓桿,不只是易讀性的槓桿。

**共置(Co-location)** 是檔案內的搭檔:階梯決定一塊內容放_多遠的下方_,共置則決定它到了那裡之後_旁邊放什麼_。把一個概念的定義、規則和注意事項放在同一個標題底下,而不是散落各處,這樣讀其中一部分就會連帶讀到它的鄰居。測試方式:這份文件讀起來應該像專門為 agent 寫的說明文件。歸在一起的素材讀起來就是那樣;散落的素材不是。(跟重複不同:重複是把一個意思放在兩個地方;散落是把一個意思碎裂到很多地方。)

**蔓延(Sprawl)** 是這裡的失敗模式:文件就是太長,就算每一行都有用、都獨一無二。注意力會在多出來的部分被稀釋,而每多一行就多一行要維持相關。解法是階梯:把參考揭露到指標後面,並依分支或順序拆開,讓每條路徑只帶它需要的東西。

## 步驟與完成標準

每個步驟都以**完成標準(completion criterion)** 結束,也就是告訴 agent 工作完成了的條件。兩個性質讓它成為槓桿:

- **清晰度**:agent 分得出做完和沒做完嗎?模糊的界線(「達到理解」)會招來**提早完成**:在真正做完之前就結束步驟,注意力滑向_做完_這件事。眼前還看得到的後續步驟(**完成後步驟**)提供拉力;標準的清晰度是阻力。依序防守:**先把界線磨利**(局部又便宜);只有當它無法再消除模糊、_而且_你觀察到趕工的情況時,才用拆開順序的方式把後面的步驟藏起來。藏起來只有跨越真正的 context 邊界才有用(交接或 subagent 派遣;inline 呼叫會讓後面的步驟留在 context 裡,什麼都沒清掉)。
- **要求度**:它要求多少。「每個被修改的 model 都交代清楚」會逼出徹底的工作,「產出一份變更清單」就不會。要求度驅動**苦工(legwork)**(agent 在工作中做的挖掘,潛藏在措辭裡,而不是寫成獨立的步驟),而且它不受步驟限制:「每條規則都套用過」約束一整批扁平的參考,就像「每個步驟都做完」約束一個順序一樣,這就是為什麼全是參考的文件也能帶有窮盡的標準。

最強的標準是既可檢查、又窮盡的。

## 什麼時候拆

把一份文件拆成兩份,會花掉兩種負載的其中一種,所以只有在這刀切得值得時才拆:

- **依順序**:當一連串步驟裡,完成後的步驟會誘使 agent 趕著做眼前這一步時,就把它拆開。讓它們不在視線內,會推動對目前任務做更多苦工。要小心反過來的情況:合併順序會讓每個步驟都看得到後面的步驟,招來提早完成。
- **依呼叫方式**,skill 特有:見 [`SKILL-MECHANICS.md`](SKILL-MECHANICS.md)。

## 主導詞

**主導詞(leading word)** 是一個精簡的概念,已經存在於模型的預訓練裡,agent 在執行文件時用它來思考(_lesson_、_fog of war_、_tracer bullets_)。把它當成 token 重複使用,絕不當成句子,它會累積出一個分散式的定義,用最少的 token 錨定一整個區域的行為,方法是召喚模型已經持有的先驗。自己造詞只要你定義得清楚也行,但自創的詞召喚不到任何先驗:預訓練的詞免費給你的東西,你得用定義的 token 來付;先找現成的詞。

它錨定兩次。在本文裡是_執行_:每次這個詞出現,agent 都會去拿同樣的行為,而在扁平的參考裡,它會把注意力集中在要找的那一類東西上。在指標裡是_呼叫_:當同一個詞同時出現在你的 prompt、你的文件和你的 codebase 裡,agent 會把這個共用語言連到那份素材,更可靠地找到它。

去找可以用主導詞重構的機會。在三個地方展開寫出來的三件組,一個花一整句話去比劃某個想法的指標。每一個都是在呼喊著要塌縮成單一 token 的段落:

- 「快速、deterministic、低開銷」→ _tight_(一個 _tight_ 的迴圈)。
- 「一個你相信的迴圈」→ _red_,把模糊的關卡變成二元的可觀察狀態(迴圈在這個 bug 上會變 _red_,或不會)。

你贏兩次:token 變少,而且 agent 有了更銳利的鉤子可以掛上它的思考。假設每份文件都帶著可以被主導詞淘汰的重述。去把它們找出來。

**否定(Negation)** 是這個槓桿旁邊的失敗模式:用禁止來引導,會把被禁止的行為拖進 context,讓它變得_更_容易被取用,而不是更少。_不要想大象_,結果滿腦子都是大象;否定是個很弱的修飾語,被強烈啟動的概念壓過去了,所以禁令有一半被讀成要去做那件事的指示。要提示**正面**:陳述目標行為(「寫一行的註解」),這樣被禁止的行為就永遠不會被說出口。禁令只有在它是你無法用正面措辭表達的硬性護欄時才有存在的資格;就算那樣,也要搭配正面的目標,讓注意力落在該做什麼。

## 修剪

- 讓每個意思都維持在**單一事實來源(single source of truth)**:一個權威的地方,這樣改變行為就只要改一處。**重複**(同一個意思在多個地方)會花維護成本和 token,並把一個意思在階梯上的突出程度膨脹到超過它真正的排名。(這是主導詞的意外反面,主導詞是刻意重複一個 token,絕不重複意思。)
- **環境**也是事實來源(`package.json` 的 scripts、設定檔、目錄配置、`--help` 的輸出),重述它的文件就是個**快取(cache)**:查詢結果的副本,只有當查詢很昂貴時才值得佔那份負載。快取 agent 靠找也找不到的東西:不成文的慣例、某個選擇背後的理由、沒有任何設定檔會招認的陷阱。把一個檔案、一個指令就能查到的留給環境,在那裡它們不會過時。
- 檢查每一行的**相關性**:它是否仍然跟文件在做的事有關?一行失去相關性,要嘛是因為它從來就跟任務無關(純粹的說明,或是應該被揭露的分支),要嘛是因為它描述的行為或世界變了而過時。越短的文件越容易維持相關。沒有修剪的紀律,預設的下場就是**沉積(sediment)**:過時的層層堆積,因為新增感覺安全、移除感覺有風險,直到你必須往下鑿穿它們才能找到還有用的東西。
- 逐句獵殺**無效句(no-op)**:模型本來就預設會遵守的指示,付了負載卻什麼都沒說。測試(它跟預設相比有沒有改變行為?)是相對於模型的,不是相對於讀者的:兩個人對某個無效句有不同意見,是因為對預設行為有不同意見,要用實際執行文件來解決,不是用辯論。當一個句子沒通過,就把整句刪掉,不要在裡面修剪字詞。這個測試也會評分主導詞:一個力道弱到打不贏預設的詞(agent 本來就算徹底的時候說 _be thorough_)就是無效句,修法是換一個更強的詞(_relentless_),不是換一種技巧。

英文原文

---
name: writing-for-agents
description: Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.
---

Reference for writing any document an agent consumes: a skill, an `AGENTS.md` / `CLAUDE.md`, a doc reached by a pointer. The packaging differs; the writing does not: the same levers make each one predictable, since the agent takes the same _process_ every run rather than producing the same output.

When the document you're writing is a skill, read [`SKILL-MECHANICS.md`](SKILL-MECHANICS.md) for frontmatter, invocation choice, and router skills.

## Context pointers

A **context pointer** is a reference held in the agent's context that names some out-of-context material and encodes the condition for reaching it. A skill's description is one; a line in `AGENTS.md` naming a doc is the same object. The pointer's _wording_, not its target, decides when the agent reaches the material, and how reliably. A must-have target behind a weakly worded pointer is a variance bug: sharpen the wording first, and inline the material only if sharpening fails.

A pointer does two jobs: state what the material is, and list the **branches** that should trigger reaching it (a branch is a distinct case the document handles, so different runs take different paths through it). Every word of an always-loaded pointer costs on every turn, so it earns even harder pruning than the body:

- **Front-load the leading word**: the pointer is where it does its triggering work.
- **One trigger per branch.** Synonyms that rename a single branch are one branch written twice; collapse them and keep only genuinely distinct branches.
- **Cut identity the body already carries.**

## The two loads

Every document and pointer you add spends one of two budgets:

- **Context load** is the cost of always-loaded material on the agent's window: an `AGENTS.md` line, a skill description, anything sitting in context every turn, spending tokens and attention whether or not it fires.
- **Cognitive load** is the cost on the human: which documents exist and when to reach for each. The human is the index. Not a cost to minimise: it is the price of human agency; spend it where human judgement matters, remove it where it does not.

Material reached only through a pointer escapes context load at the price of the pointer's own line; material with no pointer at all rides entirely on cognitive load.

## Information hierarchy

A document is built from two content types: **steps** (the ordered actions the agent performs) and **reference** (definitions, rules, facts consulted on demand). The two mix freely: all steps (a recipe), all reference (a review's rules, this skill), or both. The core decision is where each piece sits on the **information hierarchy**, a ladder ranked by how immediately the agent needs the material:

1. **In-file step** is the primary tier: what the agent does, in order.
2. **In-file reference** is consulted on demand. Often a legitimately flat peer-set (every rule of a review on one rung), which is a fine arrangement, not a smell.
3. **Disclosed reference** is pushed out into a separate file, reached by a context pointer, loaded only when the pointer fires. Spans a sibling file in the same folder through fully external reference that lives anywhere and any document can point at.

Push too little down and the top bloats; push too much and you hide material the agent actually needs. That tension is the whole decision.

**Progressive disclosure** is the move down the ladder (out of the main file and behind a pointer) so the top stays legible. Not primarily a token optimisation: it is how the hierarchy is protected. Branching is the cleanest disclosure test: inline what every branch needs, and push behind a pointer what only some branches reach. When a document has steps, in-file reference that should be disclosed buries them and turns attending to them into a coin-flip: a variance lever, not just a legibility one.

**Co-location** is the within-file companion: where the ladder decides _how far down_ a piece sits, co-location decides _what sits beside it_ once there. Keep a concept's definition, rules, and caveats under one heading rather than scattered, so reading one part brings its neighbours with it. The test: the document should read like documentation written for the agent. Grouped material reads that way; scattered material does not. (Distinct from duplication: that repeats one meaning in two places; scattering fragments one meaning across many.)

**Sprawl** is the failure mode here: a document simply too long, even when every line is live and unique. Attention thins across the excess, and every extra line is one more to keep relevant. The cure is the ladder: disclose reference behind pointers, and split by branch or sequence so each path carries only what it needs.

## Steps and completion criteria

Every step ends on a **completion criterion**, the condition that tells the agent the work is done. Two properties make it a lever:

- **Clarity**: can the agent tell done from not-done? A vague bound ("understanding reached") invites **premature completion**: ending the step before it is genuinely done, attention slipping to _being done_. The visible steps still ahead (the **post-completion steps**) supply the pull; the criterion's clarity is the resistance. Defend in order: **sharpen the bound first** (local and cheap); only if it is irreducibly fuzzy _and_ you observe the rush, hide the later steps by splitting the sequence. Hiding only works across a real context boundary (a hand-off or a subagent dispatch; an inline call leaves the later steps in context and clears nothing).
- **Demand**: how much it requires. "Every modified model accounted for" forces thorough work where "produce a change list" does not. Demand drives **legwork** (the digging the agent does within the work, latent in the wording rather than written as its own step), and it is not step-bound: "every rule applied" binds a body of flat reference just as "every step done" binds a sequence, which is how an all-reference document still carries an exhaustiveness bar.

The strongest criteria are both checkable and exhaustive.

## When to split

Splitting one document into two spends one of the two loads, so split only when the cut earns it:

- **By sequence**: split a run of steps where the post-completion steps tempt the agent to rush the one in front of it. Keeping them out of view drives more legwork on the current task. Beware the reverse: merging sequences exposes each step's later steps to what follows, inviting premature completion.
- **By invocation**, skill-specific: see [`SKILL-MECHANICS.md`](SKILL-MECHANICS.md).

## Leading words

A **leading word** is a compact concept already living in the model's pretraining that the agent thinks with while running the document (_lesson_, _fog of war_, _tracer bullets_). Repeated as a token, never as a sentence, it accumulates a distributed definition and anchors a whole region of behaviour in the fewest tokens, by recruiting priors the model already holds. Coining your own works if you define it clearly, but a made-up word recruits no priors: you pay in definition tokens what a pretrained word gives free; reach for an existing word first.

It anchors twice. In the body, _execution_: the agent reaches for the same behaviour every time the word appears, and inside flat reference it focuses attention on a class of thing to look for. In a pointer, _invocation_: when the same word lives in your prompts, your docs, and your codebase, the agent links that shared language to the material and reaches it more reliably.

Hunt for opportunities to refactor with leading words. A triad spelled out at three sites, a pointer spending a sentence to gesture at one idea. Each is a passage begging to collapse into a single token:

- "fast, deterministic, low-overhead" → _tight_ (a _tight_ loop).
- "a loop you believe in" → _red_, turning a fuzzy gate into a binary observable state (the loop goes _red_ on the bug, or it doesn't).

You win twice: fewer tokens, and a sharper hook for the agent to hang its thinking on. Assume every document is carrying restatements that leading words retire. Go find them.

**Negation** is the failure mode beside this lever: steering by prohibition drags the forbidden behaviour into context and makes it _more_ available, not less. _Don't think of an elephant_, and the elephant is all there is; the negation is a weak modifier the strongly-activated concept overruns, so the ban half-reads as an instruction to do the thing. Prompt the **positive**: state the target behaviour ("write one-line comments") so the banned one is never spoken. A prohibition earns its place only as a hard guardrail you cannot phrase positively; even then, pair it with the positive target so attention lands on what to do.

## Pruning

- Keep each meaning in a **single source of truth**: one authoritative place, so changing the behaviour is a one-place edit. **Duplication** (the same meaning in more than one place) costs maintenance and tokens, and inflates a meaning's prominence on the ladder past its real rank. (The accidental inverse of a leading word, which repeats a token on purpose, never the meaning.)
- The **environment** is a source of truth too (`package.json` scripts, config files, the directory layout, `--help` output), and a document that restates it is a **cache**: a copy of a lookup, earning its load only when the lookup is expensive. Cache what the agent cannot find by looking: the unwritten convention, the reason behind a choice, the gotcha no config confesses. Leave the one-file, one-command lookups to the environment, where they cannot go stale.
- Check every line for **relevance**: does it still bear on what the document does? A line loses relevance by never bearing on the task (mere exposition, or a branch that should be disclosed) or by going stale as the behaviour or world it describes changes. Shorter documents are easier to keep relevant. Without a pruning discipline the default fate is **sediment**: stale layers that settle because adding feels safe and removing feels risky, until you must core down through them to find what is still live.
- Hunt **no-ops** sentence by sentence: an instruction the model already obeys by default pays load to say nothing. The test (does it change behaviour versus the default?) is model-relative, not reader-relative: two people disagreeing about a no-op disagree about the default, and settle it by running the document, not by debate. When a sentence fails, delete the whole sentence rather than trim words from it. The test also grades leading words: a word too weak to beat the default (_be thorough_ when the agent is already thorough-ish) is a no-op, and the fix is a stronger word (_relentless_), not a different technique.