Learn how to write effective Skills that agents can discover and use successfully.
了解如何撰寫能讓代理發現並成功使用的有效技能。
Good Skills are concise, well-structured, and tested with real usage. This guide provides practical authoring decisions to help you write Skills that agents can discover and use effectively.
好的技能簡潔、結構良好,並以真實使用情境測試過。本指南提供實務的撰寫決策,幫助你寫出代理能發現並有效使用的技能。
For conceptual background on how Skills work, see the Skills overview.
關於技能運作方式的背景概念,請見 技能總覽。
The context window is a public good. Your Skill shares the context window with everything else your agent needs to know, including:
上下文視窗是公共財。你的技能與代理需要知道的所有其他事物共享上下文視窗,包括:
Not every token in your Skill has an immediate cost. At startup, only the metadata (name and description) from all Skills is pre-loaded. Agents read SKILL.md only when the Skill becomes relevant, and read additional files only as needed. However, being concise in SKILL.md still matters: once an agent loads it, every token competes with conversation history and other context.
並非技能中的每個 token 都有立即成本。啟動時,只會預先載入所有技能的 metadata(name 與 description)。代理只在技能變得相關時才會讀取 SKILL.md,而且只在需要時讀取其他檔案。不過,讓 SKILL.md 保持簡潔仍然重要:一旦代理載入它,每個 token 都會與對話歷史及其他上下文競爭。
Default assumption: Agents are already very smart
預設假設:代理已經非常聰明
Only add context agents don't already have. Challenge each piece of information:
只加入代理尚未擁有的上下文。質疑每一則資訊:
Good example: Concise (approximately 50 tokens):
好範例:簡潔(約 50 tokens):
````markdown theme={null}
Use pdfplumber for text extraction:
```python
````markdown theme={null}
Use pdfplumber for text extraction:
```python
import pdfplumber
import pdfplumber
with pdfplumber.open("file.pdf") as pdf: text = pdf.pages[0].extract_text() ``` ````
with pdfplumber.open("file.pdf") as pdf: text = pdf.pages[0].extract_text() ``` ````
Bad example: Too verbose (approximately 150 tokens):
壞範例:過於冗長(約 150 tokens):
```markdown theme={null}
PDF (Portable Document Format) files are a common file format that contains text, images, and other content. To extract text from a PDF, you'll need to use a library. There are many libraries available for PDF processing, but we recommend pdfplumber because it's easy to use and handles most cases well. First, you'll need to install it using pip. Then you can use the code below... ```
```markdown theme={null}
PDF (Portable Document Format) files are a common file format that contains text, images, and other content. To extract text from a PDF, you'll need to use a library. There are many libraries available for PDF processing, but we recommend pdfplumber because it's easy to use and handles most cases well. First, you'll need to install it using pip. Then you can use the code below... ```
The concise version assumes the agent knows what PDFs are and how libraries work.
簡潔版本假設代理知道什麼是 PDF,以及函式庫如何運作。
Match the level of specificity to the task's fragility and variability.
讓具體程度對應任務的脆弱性與變異性。
High freedom (text-based instructions):
高自由度(文字式指令):
Use when:
使用時機:
Example:
範例:
```markdown theme={null}
```markdown theme={null}
Medium freedom (pseudocode or scripts with parameters):
中自由度(帶參數的虛擬碼或腳本):
Use when:
使用時機:
Example:
範例:
````markdown theme={null}
Use this template and customize as needed:
```python
````markdown theme={null}
Use this template and customize as needed:
```python
def generate_report(data, format="markdown", include_charts=True): # Process data # Generate output in specified format # Optionally include visualizations ``` ````
def generate_report(data, format="markdown", include_charts=True): # Process data # Generate output in specified format # Optionally include visualizations ``` ````
Low freedom (specific scripts, few or no parameters):
低自由度(特定腳本,極少或沒有參數):
Use when:
使用時機:
Example:
範例:
````markdown theme={null}
Run exactly this script:
```bash
````markdown theme={null}
Run exactly this script:
```bash
python scripts/migrate.py --verify --backup ```
python scripts/migrate.py --verify --backup ```
Do not modify the command or add additional flags. ````
Do not modify the command or add additional flags. ````
Analogy: Think of the agent as a robot exploring a path:
類比:把代理想像成在探索路徑的機器人:
Skills act as additions to models, so effectiveness depends on the underlying model. Test your Skill with all the models you plan to use it with.
技能是模型的附加物,因此有效性取決於底層模型。用你打算與技能一起使用的所有模型來測試你的技能。
Testing considerations by model:
各模型的測試考量:
What works perfectly for Opus might need more detail for Haiku. If you plan to use your Skill across multiple models, aim for instructions that work well with all of them.
對 Opus 完美的內容,對 Haiku 可能需要更多細節。若你打算在多個模型上使用技能,目標是寫出對它們全部都適用的指令。
name - Human-readable name of the Skill (64 characters maximum)description - One-line description of what the Skill does and when to use it (1024 characters maximum)For complete Skill structure details, see the Skills overview.
name - 技能的人類可讀名稱(最多 64 字元)description - 一行描述技能做什麼以及何時使用(最多 1024 字元)完整的技能結構細節,請見技能總覽。
Use consistent naming patterns to make Skills easier to reference and discuss. We recommend using gerund form (verb + -ing) for Skill names, as this clearly describes the activity or capability the Skill provides.
使用一致的命名模式,讓技能更容易被引用與討論。我們建議技能名稱採用動名詞形式(動詞 + -ing),因為這能清楚描述技能所提供的活動或能力。
Good naming examples (gerund form):
好的命名範例(動名詞形式):
Acceptable alternatives:
可接受的替代方案:
Avoid:
避免:
Consistent naming makes it easier to:
一致的命名能讓你更容易:
The description field enables Skill discovery and should include both what the Skill does and when to use it.
description 欄位促成技能的探索,應同時包含技能做什麼與何時使用。
Be specific and include key terms. Include both what the Skill does and specific triggers/contexts for when to use it.
要具體並包含關鍵詞。同時包含技能做什麼,以及具體的觸發條件/上下文來說明何時使用。
Each Skill has exactly one description field. The description is critical for skill selection: agents use it to choose the right Skill from potentially 100+ available Skills. Your description must provide enough detail for an agent to know when to select this Skill, while the rest of SKILL.md provides the implementation details.
每個技能恰好只有一個 description 欄位。description 對技能選擇至關重要:代理會用它從可能有 100+ 個可用技能中選出正確的那個。你的 description 必須提供足夠的細節,讓代理知道何時該選擇這個技能,而 SKILL.md 的其餘部分則提供實作細節。
Effective examples:
有效的範例:
PDF Processing skill:
PDF 處理技能:
yaml theme={null}
description: Extract text and tables from PDF files, fill forms, merge documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction.
yaml theme={null}
description: Extract text and tables from PDF files, fill forms, merge documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction.
Excel Analysis skill:
Excel 分析技能:
yaml theme={null}
description: Analyze Excel spreadsheets, create pivot tables, generate charts. Use when analyzing Excel files, spreadsheets, tabular data, or .xlsx files.
yaml theme={null}
description: Analyze Excel spreadsheets, create pivot tables, generate charts. Use when analyzing Excel files, spreadsheets, tabular data, or .xlsx files.
Git Commit Helper skill:
Git Commit Helper 技能:
yaml theme={null}
description: Generate descriptive commit messages by analyzing git diffs. Use when the user asks for help writing commit messages or reviewing staged changes.
yaml theme={null}
description: Generate descriptive commit messages by analyzing git diffs. Use when the user asks for help writing commit messages or reviewing staged changes.
Avoid vague descriptions like these:
避免像這樣的含糊 description:
yaml theme={null}
description: Helps with documents
yaml theme={null}
description: Helps with documents
yaml theme={null}
description: Processes data
yaml theme={null}
description: Processes data
yaml theme={null}
description: Does stuff with files
yaml theme={null}
description: Does stuff with files
SKILL.md serves as an overview that points agents to detailed materials as needed, like a table of contents in an onboarding guide. For an explanation of how progressive disclosure works, see How Skills work in the overview.
SKILL.md 作為一個總覽,在需要時把代理引導到詳細資料,就像入門指南中的目錄。關於漸進揭露如何運作的說明,請見總覽中的技能如何運作。
Practical guidance:
實務指引:
A basic Skill starts with just a SKILL.md file containing metadata and instructions:
基礎技能只從一個包含 metadata 與指令的 SKILL.md 檔案開始:

As your Skill grows, you can bundle additional content that agents load only when needed:

The complete Skill directory structure might look like this:
pdf/
├── SKILL.md # Main instructions (loaded when triggered)
├── FORMS.md # Form-filling guide (loaded as needed)
├── reference.md # API reference (loaded as needed)
├── examples.md # Usage examples (loaded as needed)
└── scripts/
├── analyze_form.py # Utility script (executed, not loaded)
├── fill_form.py # Form filling script
└── validate.py # Validation script
name: PDF Processing description: Extracts text and tables from PDF files, fills forms, and merges documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction.
Extract text with pdfplumber:
import pdfplumber
with pdfplumber.open("file.pdf") as pdf:
text = pdf.pages[0].extract_text()
Form filling: See FORMS.md for complete guide API reference: See REFERENCE.md for all methods Examples: See EXAMPLES.md for common patterns
Agents load FORMS.md, REFERENCE.md, or EXAMPLES.md only when needed.
#### Pattern 2: Domain-specific organization
For Skills with multiple domains, organize content by domain to avoid loading irrelevant context. When a user asks about sales metrics, the agent only needs to read sales-related schemas, not finance or marketing data. This keeps token usage low and context focused.
```
bigquery-skill/
├── SKILL.md (overview and navigation)
└── reference/
├── finance.md (revenue, billing metrics)
├── sales.md (opportunities, pipeline)
├── product.md (API usage, features)
└── marketing.md (campaigns, attribution)
```
````markdown SKILL.md theme={null}
# BigQuery Data Analysis
## Available datasets
**Finance**: Revenue, ARR, billing → See [reference/finance.md](reference/finance.md)
**Sales**: Opportunities, pipeline, accounts → See [reference/sales.md](reference/sales.md)
**Product**: API usage, features, adoption → See [reference/product.md](reference/product.md)
**Marketing**: Campaigns, attribution, email → See [reference/marketing.md](reference/marketing.md)
## Quick search
Find specific metrics using grep:
```bash
grep -i "revenue" reference/finance.md
grep -i "pipeline" reference/sales.md
grep -i "api usage" reference/product.md
```
Show basic content, link to advanced content:
```markdown theme={null}
Use docx-js for new documents. See DOCX-JS.md.
For simple edits, modify the XML directly.
For tracked changes: See REDLINING.md For OOXML details: See OOXML.md
Agents read REDLINING.md or OOXML.md only when the user needs those features.
### Avoid deeply nested references
Agents may partially read files when they're referenced from other referenced files. When encountering nested references, an agent might use commands like `head -100` to preview content rather than reading entire files, resulting in incomplete information.
**Keep references one level deep from SKILL.md**. All reference files should link directly from SKILL.md to ensure agents read complete files when needed.
**Bad example: Too deep**:
```markdown theme={null}
# SKILL.md
See [advanced.md](advanced.md)...
# advanced.md
See [details.md](details.md)...
# details.md
Here's the actual information...
Good example: One level deep:
```markdown theme={null}
Basic usage: [instructions in SKILL.md] Advanced features: See advanced.md API reference: See reference.md Examples: See examples.md
### Structure longer reference files with table of contents
For reference files longer than 100 lines, include a table of contents at the top. This ensures agents can see the full scope of available information even when previewing with partial reads.
**Example**:
```markdown theme={null}
# API Reference
## Contents
- Authentication and setup
- Core methods (create, read, update, delete)
- Advanced features (batch operations, webhooks)
- Error handling patterns
- Code examples
## Authentication and setup
...
## Core methods
...
Agents can then read the complete file or jump to specific sections as needed.
For details on how this filesystem-based architecture enables progressive disclosure, see the Runtime environment section in the Advanced section below.
Break complex operations into clear, sequential steps. For particularly complex workflows, provide a checklist that the agent can copy into its response and check off as it progresses.
Example 1: Research synthesis workflow (for Skills without code):
````markdown theme={null}
Copy this checklist and track your progress:
Research Progress:
- [ ] Step 1: Read all source documents
- [ ] Step 2: Identify key themes
- [ ] Step 3: Cross-reference claims
- [ ] Step 4: Create structured summary
- [ ] Step 5: Verify citations
Step 1: Read all source documents
Review each document in the sources/ directory. Note the main arguments and supporting evidence.
Step 2: Identify key themes
Look for patterns across sources. What themes appear repeatedly? Where do sources agree or disagree?
Step 3: Cross-reference claims
For each major claim, verify it appears in the source material. Note which source supports each point.
Step 4: Create structured summary
Organize findings by theme. Include: - Main claim - Supporting evidence from sources - Conflicting viewpoints (if any)
Step 5: Verify citations
Check that every claim references the correct source document. If citations are incomplete, return to Step 3.
This example shows how workflows apply to analysis tasks that don't require code. The checklist pattern works for any complex, multi-step process.
**Example 2: PDF form filling workflow** (for Skills with code):
````markdown theme={null}
## PDF form filling workflow
Copy this checklist and check off items as you complete them:
```
Task Progress:
- [ ] Step 1: Analyze the form (run analyze_form.py)
- [ ] Step 2: Create field mapping (edit fields.json)
- [ ] Step 3: Validate mapping (run validate_fields.py)
- [ ] Step 4: Fill the form (run fill_form.py)
- [ ] Step 5: Verify output (run verify_output.py)
```
**Step 1: Analyze the form**
Run: `python scripts/analyze_form.py input.pdf`
This extracts form fields and their locations, saving to `fields.json`.
**Step 2: Create field mapping**
Edit `fields.json` to add values for each field.
**Step 3: Validate mapping**
Run: `python scripts/validate_fields.py fields.json`
Fix any validation errors before continuing.
**Step 4: Fill the form**
Run: `python scripts/fill_form.py input.pdf fields.json output.pdf`
**Step 5: Verify output**
Run: `python scripts/verify_output.py output.pdf`
If verification fails, return to Step 2.
Clear steps prevent agents from skipping critical validation. The checklist helps both you and the agent track progress through multi-step workflows.
Common pattern: Run validator → fix errors → repeat
This pattern greatly improves output quality.
Example 1: Style guide compliance (for Skills without code):
```markdown theme={null}
This shows the validation loop pattern using reference documents instead of scripts. The "validator" is STYLE\_GUIDE.md, and the agent performs the check by reading and comparing.
**Example 2: Document editing process** (for Skills with code):
```markdown theme={null}
## Document editing process
1. Make your edits to `word/document.xml`
2. **Validate immediately**: `python ooxml/scripts/validate.py unpacked_dir/`
3. If validation fails:
- Review the error message carefully
- Fix the issues in the XML
- Run validation again
4. **Only proceed when validation passes**
5. Rebuild: `python ooxml/scripts/pack.py unpacked_dir/ output.docx`
6. Test the output document
The validation loop catches errors early.
Don't include information that will become outdated:
Bad example: Time-sensitive (will become wrong):
```markdown theme={null} If you're doing this before August 2025, use the old API. After August 2025, use the new API.
**Good example** (use "old patterns" section):
```markdown theme={null}
## Current method
Use the v2 API endpoint: `api.example.com/v2/messages`
## Old patterns
<details>
<summary>Legacy v1 API (deprecated 2025-08)</summary>
The v1 API used: `api.example.com/v1/messages`
This endpoint is no longer supported.
</details>
The old patterns section provides historical context without cluttering the main content.
Choose one term and use it throughout the Skill:
Good - Consistent:
Bad - Inconsistent:
Consistency helps agents understand and follow instructions.
Provide templates for output format. Match the level of strictness to your needs.
For strict requirements (like API responses or data formats):
````markdown theme={null}
ALWAYS use this exact template structure:
# [Analysis Title]
## Executive summary
[One-paragraph overview of key findings]
## Key findings
- Finding 1 with supporting data
- Finding 2 with supporting data
- Finding 3 with supporting data
## Recommendations
1. Specific actionable recommendation
2. Specific actionable recommendation
**For flexible guidance** (when adaptation is useful):
````markdown theme={null}
## Report structure
Here is a sensible default format, but use your best judgment based on the analysis:
```markdown
# [Analysis Title]
## Executive summary
[Overview]
## Key findings
[Adapt sections based on what you discover]
## Recommendations
[Tailor to the specific context]
```
Adjust sections as needed for the specific analysis type.
For Skills where output quality depends on seeing examples, provide input/output pairs just like in regular prompting:
````markdown theme={null}
Generate commit messages following these examples:
Example 1: Input: Added user authentication with JWT tokens Output:
feat(auth): implement JWT-based authentication
Add login endpoint and token validation middleware
Example 2: Input: Fixed bug where dates displayed incorrectly in reports Output:
fix(reports): correct date formatting in timezone conversion
Use UTC timestamps consistently across report generation
Example 3: Input: Updated dependencies and refactored error handling Output:
chore: update dependencies and refactor error handling
- Upgrade lodash to 4.17.21
- Standardize error response format across endpoints
Follow this style: type(scope): brief description, then detailed explanation.
Examples help agents understand the desired style and level of detail more clearly than descriptions alone.
### Conditional workflow pattern
Guide agents through decision points:
```markdown theme={null}
## Document modification workflow
1. Determine the modification type:
**Creating new content?** → Follow "Creation workflow" below
**Editing existing content?** → Follow "Editing workflow" below
2. Creation workflow:
- Use docx-js library
- Build document from scratch
- Export to .docx format
3. Editing workflow:
- Unpack existing document
- Modify XML directly
- Validate after each change
- Repack when complete
```
<Tip>
If workflows become large or complicated with many steps, consider pushing them into separate files and tell the agent to read the appropriate file based on the task at hand.
</Tip>
## Evaluation and iteration
### Build evaluations first
**Create evaluations BEFORE writing extensive documentation.** This ensures your Skill solves real problems rather than documenting imagined ones.
**Evaluation-driven development:**
1. **Identify gaps**: Run your agent on representative tasks without a Skill. Document specific failures or missing context
2. **Create evaluations**: Build three scenarios that test these gaps
3. **Establish baseline**: Measure the agent's performance without the Skill
4. **Write minimal instructions**: Create just enough content to address the gaps and pass evaluations
5. **Iterate**: Execute evaluations, compare against baseline, and refine
This approach ensures you're solving actual problems rather than anticipating requirements that may never materialize.
**Evaluation structure**:
```json theme={null}
{
"skills": ["pdf-processing"],
"query": "Extract all text from this PDF file and save it to output.txt",
"files": ["test-files/document.pdf"],
"expected_behavior": [
"Successfully reads the PDF file using an appropriate PDF processing library or command-line tool",
"Extracts text content from all pages in the document without missing any pages",
"Saves the extracted text to a file named output.txt in a clear, readable format"
]
}
```
<Note>
This example demonstrates a data-driven evaluation with a simple testing rubric. We do not currently provide a built-in way to run these evaluations. Users can create their own evaluation system. Evaluations are your source of truth for measuring Skill effectiveness.
</Note>
### Develop Skills iteratively with the agent
The most effective Skill development process involves the agent itself. Work with one instance ("Agent A") to create a Skill that will be used by other instances ("Agent B"). Agent A helps you design and refine instructions, while Agent B tests them in real tasks. This works because the underlying models understand both how to write effective agent instructions and what information agents need.
**Creating a new Skill:**
1. **Complete a task without a Skill**: Work through a problem with Agent A using normal prompting. As you work, you'll naturally provide context, explain preferences, and share procedural knowledge. Notice what information you repeatedly provide.
2. **Identify the reusable pattern**: After completing the task, identify what context you provided that would be useful for similar future tasks.
**Example**: If you worked through a BigQuery analysis, you might have provided table names, field definitions, filtering rules (like "always exclude test accounts"), and common query patterns.
3. **Ask Agent A to create a Skill**: "Create a Skill that captures this BigQuery analysis pattern we just used. Include the table schemas, naming conventions, and the rule about filtering test accounts."
<Tip>
Modern agents understand the Skill format and structure natively. You don't need special system prompts or a "writing skills" skill to get help creating Skills. Simply ask the agent to create a Skill and it will generate properly structured SKILL.md content with appropriate frontmatter and body content.
</Tip>
4. **Review for conciseness**: Check that Agent A hasn't added unnecessary explanations. Ask: "Remove the explanation about what win rate means - the agent already knows that."
5. **Improve information architecture**: Ask Agent A to organize the content more effectively. For example: "Organize this so the table schema is in a separate reference file. We might add more tables later."
6. **Test on similar tasks**: Use the Skill with Agent B (a fresh instance with the Skill loaded) on related use cases. Observe whether Agent B finds the right information, applies rules correctly, and handles the task successfully.
7. **Iterate based on observation**: If Agent B struggles or misses something, return to Agent A with specifics: "When the agent used this Skill, it forgot to filter by date for Q4. Should we add a section about date filtering patterns?"
**Iterating on existing Skills:**
The same hierarchical pattern continues when improving Skills. You alternate between:
* **Working with Agent A** (the expert who helps refine the Skill)
* **Testing with Agent B** (the agent using the Skill to perform real work)
* **Observing Agent B's behavior** and bringing insights back to Agent A
1. **Use the Skill in real workflows**: Give Agent B (with the Skill loaded) actual tasks, not test scenarios
2. **Observe Agent B's behavior**: Note where it struggles, succeeds, or makes unexpected choices
**Example observation**: "When I asked Agent B for a regional sales report, it wrote the query but forgot to filter out test accounts, even though the Skill mentions this rule."
3. **Return to Agent A for improvements**: Share the current SKILL.md and describe what you observed. Ask: "I noticed Agent B forgot to filter test accounts when I asked for a regional report. The Skill mentions filtering, but maybe it's not prominent enough?"
4. **Review Agent A's suggestions**: Agent A might suggest reorganizing to make rules more prominent, using stronger language like "MUST filter" instead of "always filter", or restructuring the workflow section.
5. **Apply and test changes**: Update the Skill with Agent A's refinements, then test again with Agent B on similar requests
6. **Repeat based on usage**: Continue this observe-refine-test cycle as you encounter new scenarios. Each iteration improves the Skill based on real agent behavior, not assumptions.
**Gathering team feedback:**
1. Share Skills with teammates and observe their usage
2. Ask: Does the Skill activate when expected? Are instructions clear? What's missing?
3. Incorporate feedback to address blind spots in your own usage patterns
**Why this approach works**: Agent A understands agent needs, you provide domain expertise, Agent B reveals gaps through real usage, and iterative refinement improves Skills based on observed behavior rather than assumptions.
### Observe how agents navigate Skills
As you iterate on Skills, pay attention to how agents actually use them in practice. Watch for:
* **Unexpected exploration paths**: Does the agent read files in an order you didn't anticipate? This might indicate your structure isn't as intuitive as you thought
* **Missed connections**: Does the agent fail to follow references to important files? Your links might need to be more explicit or prominent
* **Overreliance on certain sections**: If the agent repeatedly reads the same file, consider whether that content should be in the main SKILL.md instead
* **Ignored content**: If the agent never accesses a bundled file, it might be unnecessary or poorly signaled in the main instructions
Iterate based on these observations rather than assumptions. The 'name' and 'description' in your Skill's metadata are particularly critical. Agents use these when deciding whether to trigger the Skill in response to the current task. Make sure they clearly describe what the Skill does and when it should be used.
## Anti-patterns to avoid
### Avoid Windows-style paths
Always use forward slashes in file paths, even on Windows:
* ✓ **Good**: `scripts/helper.py`, `reference/guide.md`
* ✗ **Avoid**: `scripts\helper.py`, `reference\guide.md`
Unix-style paths work across all platforms, while Windows-style paths cause errors on Unix systems.
### Avoid offering too many options
Don't present multiple approaches unless necessary:
````markdown theme={null}
**Bad example: Too many choices** (confusing):
"You can use pypdf, or pdfplumber, or PyMuPDF, or pdf2image, or..."
**Good example: Provide a default** (with escape hatch):
"Use pdfplumber for text extraction:
```python
import pdfplumber
```
For scanned PDFs requiring OCR, use pdf2image with pytesseract instead."
The sections below focus on Skills that include executable scripts. If your Skill uses only markdown instructions, skip to Checklist for effective Skills.
When writing scripts for Skills, handle error conditions rather than punting to the agent.
Good example: Handle errors explicitly:
```python theme={null} def process_file(path): """Process a file, creating it if it doesn't exist.""" try: with open(path) as f: return f.read() except FileNotFoundError: # Create file with default content instead of failing print(f"File {path} not found, creating default") with open(path, 'w') as f: f.write('') return '' except PermissionError: # Provide alternative instead of failing print(f"Cannot access {path}, using default") return ''
**Bad example: Punt to the agent**:
```python theme={null}
def process_file(path):
# Just fail and let the agent figure it out
return open(path).read()
Configuration parameters should also be justified and documented to avoid "voodoo constants" (Ousterhout's law). If you don't know the right value, how will the agent determine it?
Good example: Self-documenting:
```python theme={null}
REQUEST_TIMEOUT = 30
MAX_RETRIES = 3
**Bad example: Magic numbers**:
```python theme={null}
TIMEOUT = 47 # Why 47?
RETRIES = 5 # Why 5?
Even if your agent could write a script, pre-made scripts offer advantages:
Benefits of utility scripts:

The diagram above shows how executable scripts work alongside instruction files. The instruction file (forms.md) references the script, and the agent can execute it without loading its contents into context.
Important distinction: Make clear in your instructions whether the agent should:
analyze_form.py to extract fields"analyze_form.py for the field extraction algorithm"For most utility scripts, execution is preferred because it's more reliable and efficient. See the Runtime environment section below for details on how script execution works.
Example:
````markdown theme={null}
analyze_form.py: Extract all form fields from PDF
python scripts/analyze_form.py input.pdf > fields.json
Output format:
{
"field_name": {"type": "text", "x": 100, "y": 200},
"signature": {"type": "sig", "x": 150, "y": 500}
}
validate_boxes.py: Check for overlapping bounding boxes
python scripts/validate_boxes.py fields.json
# Returns: "OK" or lists conflicts
fill_form.py: Apply field values to PDF
python scripts/fill_form.py input.pdf fields.json output.pdf
### Use visual analysis
When inputs can be rendered as images, have the agent analyze them:
````markdown theme={null}
## Form layout analysis
1. Convert PDF to images:
```bash
python scripts/pdf_to_images.py form.pdf
```
2. Analyze each page image to identify form fields
3. The agent can see field locations and types visually
pdf_to_images.py script.
Agent vision capabilities help understand layouts and structures.
When agents perform complex, open-ended tasks, they can make mistakes. The "plan-validate-execute" pattern catches errors early by having the agent first create a plan in a structured format, then validate that plan with a script before executing it.
Example: Imagine asking the agent to update 50 form fields in a PDF based on a spreadsheet. Without validation, it might reference non-existent fields, create conflicting values, miss required fields, or apply updates incorrectly.
Solution: Use the workflow pattern shown above (PDF form filling), but add an intermediate changes.json file that gets validated before applying changes. The workflow becomes: analyze → create plan file → validate plan → execute → verify.
Why this pattern works:
When to use: Batch operations, destructive changes, complex validation rules, high-stakes operations.
Implementation tip: Make validation scripts verbose with specific error messages like "Field 'signature_date' not found. Available fields: customer_name, order_total, signature_date_signed" to help the agent fix issues.
Skills run in the code execution environment with platform-specific limitations:
List required packages in your SKILL.md and verify they're available in the code execution tool documentation.
Skills run in a code execution environment with filesystem access, bash commands, and code execution capabilities. For the conceptual explanation of this architecture, see The Skills architecture in the overview.
How this affects your authoring:
How agents access Skills:
reference/guide.md), not backslashesform_validation_rules.md, not doc2.mdreference/finance.md, reference/sales.mddocs/file1.md, docs/file2.mdvalidate_form.py rather than asking the agent to generate validation codeanalyze_form.py to extract fields" (execute)analyze_form.py for the extraction algorithm" (read as reference)Example:
bigquery-skill/
├── SKILL.md (overview, points to reference files)
└── reference/
├── finance.md (revenue metrics)
├── sales.md (pipeline data)
└── product.md (usage analytics)
When the user asks about revenue, the agent reads SKILL.md, sees the reference to reference/finance.md, and invokes bash to read just that file. The sales.md and product.md files remain on the filesystem, consuming zero context tokens until needed. This filesystem-based model is what enables progressive disclosure. Agents can navigate and selectively load exactly what each task requires.
For complete details on the technical architecture, see How Skills work in the Skills overview.
If your Skill uses MCP (Model Context Protocol) tools, always use fully qualified tool names to avoid "tool not found" errors.
Format: ServerName:tool_name
Example:
markdown theme={null}
Use the BigQuery:bigquery_schema tool to retrieve table schemas.
Use the GitHub:create_issue tool to create issues.
Where:
BigQuery and GitHub are MCP server namesbigquery_schema and create_issue are the tool names within those serversWithout the server prefix, agents may fail to locate the tool, especially when multiple MCP servers are available.
Don't assume packages are available:
````markdown theme={null} Bad example: Assumes installation: "Use the pdf library to process the file."
Good example: Explicit about dependencies:
"Install required package: pip install pypdf
Then use it:
python
from pypdf import PdfReader
reader = PdfReader("file.pdf")"
````
The SKILL.md frontmatter requires name (64 characters max) and description (1024 characters max) fields. See the Skills overview for complete structure details.
Keep SKILL.md body under 500 lines for optimal performance. If your content exceeds this, split it into separate files using the progressive disclosure patterns described earlier. For architectural details, see the Skills overview.
Before sharing a Skill, verify:

隨著技能成長,你可以打包額外內容,讓代理只在需要時載入:

完整的技能目錄結構可能看起來像這樣:
pdf/
├── SKILL.md # Main instructions (loaded when triggered)
├── FORMS.md # Form-filling guide (loaded as needed)
├── reference.md # API reference (loaded as needed)
├── examples.md # Usage examples (loaded as needed)
└── scripts/
├── analyze_form.py # Utility script (executed, not loaded)
├── fill_form.py # Form filling script
└── validate.py # Validation script
name: PDF Processing description: Extracts text and tables from PDF files, fills forms, and merges documents. Use when working with PDF files or when the user mentions PDFs, forms, or document extraction.
Extract text with pdfplumber:
import pdfplumber
with pdfplumber.open("file.pdf") as pdf:
text = pdf.pages[0].extract_text()
Form filling: See FORMS.md for complete guide API reference: See REFERENCE.md for all methods Examples: See EXAMPLES.md for common patterns
代理只在需要時才載入 FORMS.md、REFERENCE.md 或 EXAMPLES.md。
#### 模式 2:依領域組織
對涵蓋多個領域的技能,依領域組織內容,避免載入不相關的上下文。當使用者問到銷售指標時,代理只需要讀取銷售相關的 schema,而不需要財務或行銷資料。這能讓 token 使用量維持在低點,並讓上下文保持聚焦。
```
bigquery-skill/
├── SKILL.md (overview and navigation)
└── reference/
├── finance.md (revenue, billing metrics)
├── sales.md (opportunities, pipeline)
├── product.md (API usage, features)
└── marketing.md (campaigns, attribution)
```
````markdown SKILL.md theme={null}
# BigQuery Data Analysis
## Available datasets
**Finance**: Revenue, ARR, billing → See [reference/finance.md](reference/finance.md)
**Sales**: Opportunities, pipeline, accounts → See [reference/sales.md](reference/sales.md)
**Product**: API usage, features, adoption → See [reference/product.md](reference/product.md)
**Marketing**: Campaigns, attribution, email → See [reference/marketing.md](reference/marketing.md)
## Quick search
Find specific metrics using grep:
```bash
grep -i "revenue" reference/finance.md
grep -i "pipeline" reference/sales.md
grep -i "api usage" reference/product.md
```
顯示基礎內容,連結到進階內容:
```markdown theme={null}
Use docx-js for new documents. See DOCX-JS.md.
For simple edits, modify the XML directly.
For tracked changes: See REDLINING.md For OOXML details: See OOXML.md
代理只在使用者需要那些功能時,才讀取 REDLINING.md 或 OOXML.md。
### 避免深層巢狀參考
當檔案從其他被參考的檔案被引用時,代理可能會部分讀取檔案。遇到巢狀參考時,代理可能會用 `head -100` 之類的指令預覽內容,而不是讀取整個檔案,導致資訊不完整。
**讓參考與 SKILL.md 保持一層深度**。所有參考檔案都應直接從 SKILL.md 連結,確保代理在需要時能讀到完整檔案。
**壞範例:太深**:
```markdown theme={null}
# SKILL.md
See [advanced.md](advanced.md)...
# advanced.md
See [details.md](details.md)...
# details.md
Here's the actual information...
好範例:一層深度:
```markdown theme={null}
Basic usage: [instructions in SKILL.md] Advanced features: See advanced.md API reference: See reference.md Examples: See examples.md
### 用目錄結構化較長的參考檔案
對超過 100 行的參考檔案,在頂端加入目錄。這能確保代理即使透過部分讀取預覽,也能看到可用資訊的完整範圍。
**範例**:
```markdown theme={null}
# API Reference
## Contents
- Authentication and setup
- Core methods (create, read, update, delete)
- Advanced features (batch operations, webhooks)
- Error handling patterns
- Code examples
## Authentication and setup
...
## Core methods
...
代理接著可以讀取完整檔案,或視需要跳到特定章節。
關於這種以檔案系統為基礎的架構如何促成漸進揭露,請見下方進階小節中的執行環境一節。
把複雜操作拆成清楚、依序的步驟。對特別複雜的工作流,提供代理可以複製到回應中並隨進度勾選的檢查清單。
範例 1:研究綜整工作流(適用於沒有程式碼的技能):
````markdown theme={null}
Copy this checklist and track your progress:
Research Progress:
- [ ] Step 1: Read all source documents
- [ ] Step 2: Identify key themes
- [ ] Step 3: Cross-reference claims
- [ ] Step 4: Create structured summary
- [ ] Step 5: Verify citations
Step 1: Read all source documents
Review each document in the sources/ directory. Note the main arguments and supporting evidence.
Step 2: Identify key themes
Look for patterns across sources. What themes appear repeatedly? Where do sources agree or disagree?
Step 3: Cross-reference claims
For each major claim, verify it appears in the source material. Note which source supports each point.
Step 4: Create structured summary
Organize findings by theme. Include: - Main claim - Supporting evidence from sources - Conflicting viewpoints (if any)
Step 5: Verify citations
Check that every claim references the correct source document. If citations are incomplete, return to Step 3.
這個範例展示了工作流如何套用於不需要程式碼的分析任務。檢查清單模式適用於任何複雜、多步驟的流程。
**範例 2:PDF 表單填寫工作流**(適用於有程式碼的技能):
````markdown theme={null}
## PDF form filling workflow
Copy this checklist and check off items as you complete them:
```
Task Progress:
- [ ] Step 1: Analyze the form (run analyze_form.py)
- [ ] Step 2: Create field mapping (edit fields.json)
- [ ] Step 3: Validate mapping (run validate_fields.py)
- [ ] Step 4: Fill the form (run fill_form.py)
- [ ] Step 5: Verify output (run verify_output.py)
```
**Step 1: Analyze the form**
Run: `python scripts/analyze_form.py input.pdf`
This extracts form fields and their locations, saving to `fields.json`.
**Step 2: Create field mapping**
Edit `fields.json` to add values for each field.
**Step 3: Validate mapping**
Run: `python scripts/validate_fields.py fields.json`
Fix any validation errors before continuing.
**Step 4: Fill the form**
Run: `python scripts/fill_form.py input.pdf fields.json output.pdf`
**Step 5: Verify output**
Run: `python scripts/verify_output.py output.pdf`
If verification fails, return to Step 2.
清楚的步驟能防止代理跳過關鍵驗證。檢查清單幫助你與代理在多步驟工作流中追蹤進度。
常見模式:執行驗證器 → 修復錯誤 → 重複
這個模式能大幅提升輸出品質。
範例 1:風格指南符合度(適用於沒有程式碼的技能):
```markdown theme={null}
這展示了使用參考文件而非腳本的驗證迴圈模式。這裡的「validator」是 STYLE\_GUIDE.md,代理透過閱讀與比對來執行檢查。
**範例 2:文件編輯流程**(適用於有程式碼的技能):
```markdown theme={null}
## Document editing process
1. Make your edits to `word/document.xml`
2. **Validate immediately**: `python ooxml/scripts/validate.py unpacked_dir/`
3. If validation fails:
- Review the error message carefully
- Fix the issues in the XML
- Run validation again
4. **Only proceed when validation passes**
5. Rebuild: `python ooxml/scripts/pack.py unpacked_dir/ output.docx`
6. Test the output document
驗證迴圈能及早捕捉錯誤。
不要包含會過時的資訊:
壞範例:對時間敏感(會變成錯的):
```markdown theme={null} If you're doing this before August 2025, use the old API. After August 2025, use the new API.
**好範例**(使用「舊模式」小節):
```markdown theme={null}
## Current method
Use the v2 API endpoint: `api.example.com/v2/messages`
## Old patterns
<details>
<summary>Legacy v1 API (deprecated 2025-08)</summary>
The v1 API used: `api.example.com/v1/messages`
This endpoint is no longer supported.
</details>
舊模式小節提供歷史脈絡,而不讓主要內容變得雜亂。
選擇一個詞,並在整個技能中一致使用:
好——一致:
壞——不一致:
一致性幫助代理理解並遵循指令。
為輸出格式提供範本。讓嚴格程度對應你的需求。
對嚴格的需求(像是 API 回應或資料格式):
````markdown theme={null}
ALWAYS use this exact template structure:
# [Analysis Title]
## Executive summary
[One-paragraph overview of key findings]
## Key findings
- Finding 1 with supporting data
- Finding 2 with supporting data
- Finding 3 with supporting data
## Recommendations
1. Specific actionable recommendation
2. Specific actionable recommendation
**對彈性的指引**(當調整有用時):
````markdown theme={null}
## Report structure
Here is a sensible default format, but use your best judgment based on the analysis:
```markdown
# [Analysis Title]
## Executive summary
[Overview]
## Key findings
[Adapt sections based on what you discover]
## Recommendations
[Tailor to the specific context]
```
Adjust sections as needed for the specific analysis type.
對輸出品質取決於看到範例的技能,提供輸入/輸出配對,就像一般的 prompt 一樣:
````markdown theme={null}
Generate commit messages following these examples:
Example 1: Input: Added user authentication with JWT tokens Output:
feat(auth): implement JWT-based authentication
Add login endpoint and token validation middleware
Example 2: Input: Fixed bug where dates displayed incorrectly in reports Output:
fix(reports): correct date formatting in timezone conversion
Use UTC timestamps consistently across report generation
Example 3: Input: Updated dependencies and refactored error handling Output:
chore: update dependencies and refactor error handling
- Upgrade lodash to 4.17.21
- Standardize error response format across endpoints
Follow this style: type(scope): brief description, then detailed explanation.
範例比單獨的描述更能幫助代理理解期望的風格與細節程度。
### 條件式工作流模式
引導代理走過決策點:
```markdown theme={null}
## Document modification workflow
1. Determine the modification type:
**Creating new content?** → Follow "Creation workflow" below
**Editing existing content?** → Follow "Editing workflow" below
2. Creation workflow:
- Use docx-js library
- Build document from scratch
- Export to .docx format
3. Editing workflow:
- Unpack existing document
- Modify XML directly
- Validate after each change
- Repack when complete
```
<Tip>
如果工作流變大或因為步驟眾多而變複雜,考慮把它們移到獨立檔案,並告訴代理依手邊的任務讀取適當的檔案。
</Tip>
## 評估與疊代
### 先建立評估
**在撰寫大量文件之前,先建立評估。**這能確保你的技能解決真實問題,而不是把想像中的問題寫成文件。
**評估驅動開發:**
1. **找出缺口**:在沒有技能的情況下,用代表性的任務執行你的代理。記錄具體的失敗或缺漏的上下文
2. **建立評估**:建立三個能測試這些缺口的場景
3. **確立基線**:在沒有技能的情況下衡量代理的表現
4. **撰寫最小指令**:只建立足以處理缺口並通過評估的內容
5. **疊代**:執行評估、與基線比較,並調整
這個方法確保你解決的是實際問題,而不是預測可能永遠不會發生的需求。
**評估結構**:
```json theme={null}
{
"skills": ["pdf-processing"],
"query": "Extract all text from this PDF file and save it to output.txt",
"files": ["test-files/document.pdf"],
"expected_behavior": [
"Successfully reads the PDF file using an appropriate PDF processing library or command-line tool",
"Extracts text content from all pages in the document without missing any pages",
"Saves the extracted text to a file named output.txt in a clear, readable format"
]
}
```
<Note>
這個範例展示了一種資料驅動的評估,帶有簡單的測試評分標準。我們目前沒有提供執行這些評估的內建方式。使用者可以建立自己的評估系統。評估是你衡量技能有效性的真相來源。
</Note>
### 與代理一起疊代式開發技能
最有效的技能開發流程涉及代理本身。與一個實例(「Agent A」)合作建立一個會被其他實例(「Agent B」)使用的技能。Agent A 幫你設計並調整指令,Agent B 在真實任務中測試它們。這之所以可行,是因為底層模型既理解如何撰寫有效的代理指令,也知道代理需要哪些資訊。
**建立一個新技能:**
1. **在沒有技能的情況下完成任務**:用正常的 prompt 與 Agent A 一起解決問題。工作過程中,你會自然提供上下文、解釋偏好、分享程序性知識。注意你重複提供了哪些資訊。
2. **找出可重用的模式**:完成任務後,找出你提供的哪些上下文對未來類似的任務有用。
**範例**:如果你做了一次 BigQuery 分析,你可能提供了資料表名稱、欄位定義、篩選規則(像是「永遠排除測試帳號」),以及常見的查詢模式。
3. **請 Agent A 建立技能**:「建立一個捕捉我們剛剛使用的 BigQuery 分析模式的技能。包含資料表 schema、命名慣例,以及關於篩選測試帳號的規則。」
<Tip>
現代代理天生就理解技能格式與結構。你不需要特殊的 system prompt 或「writing skills」技能來獲得建立技能的協助。只要請代理建立技能,它就會產生結構正確的 SKILL.md 內容,帶有適當的 frontmatter 與本體內容。
</Tip>
4. **檢查簡潔度**:確認 Agent A 沒有加入不必要的解釋。詢問:「移除關於 win rate 是什麼意思的解釋——代理已經知道了。」
5. **改善資訊架構**:請 Agent A 更有效地組織內容。例如:「把這個組織成資料表 schema 放在獨立的參考檔案。我們之後可能會加入更多資料表。」
6. **在類似的任務上測試**:在相關的使用案例上,用 Agent B(一個載入技能的乾淨實例)使用這個技能。觀察 Agent B 是否找到正確資訊、正確套用規則,並成功處理任務。
7. **依觀察疊代**:如果 Agent B 卡住或漏掉某些東西,帶著具體細節回到 Agent A:「當代理使用這個技能時,它忘了用日期篩選 Q4。我們該加一個關於日期篩選模式的小節嗎?」
**對既有技能疊代:**
同樣的階層模式在改善技能時會持續。你在以下之間交替:
* **與 Agent A 合作**(協助調整技能的專家)
* **用 Agent B 測試**(使用技能執行真實工作的代理)
* **觀察 Agent B 的行為**,並把洞察帶回給 Agent A
1. **在真實工作流中使用技能**:給 Agent B(已載入技能)實際任務,而不是測試場景
2. **觀察 Agent B 的行為**:記下它在哪裡卡住、成功,或做出意料之外的選擇
**範例觀察**:「當我請 Agent B 做區域銷售報告時,它寫了查詢,卻忘了濾掉測試帳號,即使技能提到了這條規則。」
3. **回到 Agent A 尋求改善**:分享目前的 SKILL.md 並描述你觀察到的現象。詢問:「我注意到當我請 Agent B 做區域報告時,它忘了濾掉測試帳號。技能有提到篩選,但可能還不夠顯眼?」
4. **審查 Agent A 的建議**:Agent A 可能建議重新組織讓規則更顯眼、使用更強的語言(像是「MUST filter」而非「always filter」),或重構工作流小節。
5. **套用並測試變更**:用 Agent A 的調整更新技能,然後在類似的請求上再次用 Agent B 測試
6. **依使用情況重複**:當你遇到新的情境時,持續這個觀察-調整-測試循環。每一次疊代都是根據真實的代理行為(而非假設)來改善技能。
**收集團隊回饋:**
1. 與同事分享技能,並觀察他們的使用情況
2. 詢問:技能是否在預期時觸發?指令清楚嗎?缺少什麼?
3. 把回饋納入,以處理你自己使用模式中的盲點
**這個方法為何有效**:Agent A 理解代理的需求,你提供領域專業,Agent B 透過真實使用揭露缺口,而疊代式調整根據觀察到的行為(而非假設)改善技能。
### 觀察代理如何導覽技能
當你對技能疊代時,注意代理在實務中實際如何使用它們。留意:
* **意料之外的探索路徑**:代理是否以你沒預料到的順序讀取檔案?這可能表示你的結構不如你想像中直覺
* **漏掉的連結**:代理是否沒有遵循指向重要檔案的參考?你的連結可能需要更明確或更顯眼
* **過度依賴某些小節**:如果代理重複讀取同一個檔案,考慮那些內容是否應該放進主要 SKILL.md
* **被忽略的內容**:如果代理從未存取某個打包的檔案,它可能是多餘的,或是在主要指令中沒有被清楚提示
根據這些觀察(而非假設)疊代。技能 metadata 中的 `name` 與 `description` 特別關鍵。代理在決定是否要對目前任務觸發這個技能時會用到它們。確保它們清楚描述技能做什麼以及何時該使用。
## 要避免的反模式
### 避免 Windows 風格路徑
一律在檔案路徑中使用正斜線,即使在 Windows 上也是:
* ✓ **好**:`scripts/helper.py`、`reference/guide.md`
* ✗ **避免**:`scripts\helper.py`、`reference\guide.md`
Unix 風格路徑在所有平台上都能運作,而 Windows 風格路徑在 Unix 系統上會造成錯誤。
### 避免提供太多選項
除非必要,否則不要提出多種做法:
````markdown theme={null}
**Bad example: Too many choices** (confusing):
"You can use pypdf, or pdfplumber, or PyMuPDF, or pdf2image, or..."
**Good example: Provide a default** (with escape hatch):
"Use pdfplumber for text extraction:
```python
import pdfplumber
```
For scanned PDFs requiring OCR, use pdf2image with pytesseract instead."
下方小節聚焦於包含可執行腳本的技能。如果你的技能只用 markdown 指令,跳到有效技能檢查清單。
撰寫技能腳本時,要處理錯誤情況,而不是把問題推給代理。
好範例:明確處理錯誤:
```python theme={null} def process_file(path): """Process a file, creating it if it doesn't exist.""" try: with open(path) as f: return f.read() except FileNotFoundError: # Create file with default content instead of failing print(f"File {path} not found, creating default") with open(path, 'w') as f: f.write('') return '' except PermissionError: # Provide alternative instead of failing print(f"Cannot access {path}, using default") return ''
**壞範例:推給代理**:
```python theme={null}
def process_file(path):
# Just fail and let the agent figure it out
return open(path).read()
設定參數也應該說明理由並寫上文件,以避免「巫毒常數」(Ousterhout 定律)。如果你不知道正確的值,代理要怎麼決定?
好範例:自我文件化:
```python theme={null}
REQUEST_TIMEOUT = 30
MAX_RETRIES = 3
**壞範例:魔術數字**:
```python theme={null}
TIMEOUT = 47 # Why 47?
RETRIES = 5 # Why 5?
即使你的代理可以自己寫腳本,預先做好的腳本仍提供優勢:
公用程式腳本的好處:

上方的圖展示了可執行腳本如何與指令檔案並行運作。指令檔案(forms.md)參考腳本,而代理可以在不把內容載入上下文的情況下執行它。
重要區別:在你的指令中清楚說明代理應該:
analyze_form.py to extract fields"analyze_form.py for the field extraction algorithm"對大多數公用程式腳本,執行是優先選項,因為它更可靠且更有效率。關於腳本執行如何運作的細節,請見下方的執行環境小節。
範例:
````markdown theme={null}
analyze_form.py: Extract all form fields from PDF
python scripts/analyze_form.py input.pdf > fields.json
Output format:
{
"field_name": {"type": "text", "x": 100, "y": 200},
"signature": {"type": "sig", "x": 150, "y": 500}
}
validate_boxes.py: Check for overlapping bounding boxes
python scripts/validate_boxes.py fields.json
# Returns: "OK" or lists conflicts
fill_form.py: Apply field values to PDF
python scripts/fill_form.py input.pdf fields.json output.pdf
### 使用視覺分析
當輸入可以渲染成圖片時,讓代理分析它們:
````markdown theme={null}
## Form layout analysis
1. Convert PDF to images:
```bash
python scripts/pdf_to_images.py form.pdf
```
2. Analyze each page image to identify form fields
3. The agent can see field locations and types visually
pdf_to_images.py 腳本。
代理的視覺能力有助於理解版面與結構。
當代理執行複雜、開放式的任務時,它們可能犯錯。「計畫-驗證-執行」模式讓代理先用結構化格式建立計畫,再用腳本驗證該計畫,然後才執行,藉此及早捕捉錯誤。
範例:想像請代理根據一份試算表更新 PDF 中的 50 個表單欄位。沒有驗證的話,它可能會引用不存在的欄位、建立衝突的值、漏掉必填欄位,或錯誤地套用更新。
解決方案:使用上面展示的工作流模式(PDF 表單填寫),但加入一個在套用變更前先被驗證的中間 changes.json 檔案。工作流變成:分析 → 建立計畫檔案 → 驗證計畫 → 執行 → 驗證。
這個模式為何有效:
使用時機:批次操作、破壞性變更、複雜的驗證規則、高風險操作。
實作提示:讓驗證腳本詳細,帶有特定的錯誤訊息,像是 "Field 'signature_date' not found. Available fields: customer_name, order_total, signature_date_signed",以幫助代理修復問題。
技能在程式碼執行環境中執行,帶有平台特定限制:
在 SKILL.md 中列出所需的套件,並確認它們在程式碼執行工具文件中可用。
技能在帶有檔案系統存取、bash 指令與程式碼執行能力的程式碼執行環境中執行。關於這個架構的概念說明,請見總覽中的技能架構。
這如何影響你的撰寫:
代理如何存取技能:
reference/guide.md),不要用反斜線form_validation_rules.md,而不是 doc2.mdreference/finance.md、reference/sales.mddocs/file1.md、docs/file2.mdvalidate_form.py,而不是要求代理產生驗證程式碼analyze_form.py to extract fields"(執行)analyze_form.py for the extraction algorithm"(作為參考閱讀)範例:
bigquery-skill/
├── SKILL.md (overview, points to reference files)
└── reference/
├── finance.md (revenue metrics)
├── sales.md (pipeline data)
└── product.md (usage analytics)
當使用者問到營收時,代理讀取 SKILL.md、看到指向 reference/finance.md 的參考,並呼叫 bash 只讀取那個檔案。sales.md 與 product.md 留在檔案系統上,在需要前不消耗任何上下文 tokens。這個以檔案系統為基礎的模型正是漸進揭露之所以可行的原因。代理可以導覽並選擇性地載入每個任務所需的確切內容。
技術架構的完整細節,請見技能總覽中的技能如何運作。
如果你的技能使用 MCP(Model Context Protocol)工具,永遠使用完整限定的工具名稱,以避免「tool not found」錯誤。
格式:ServerName:tool_name
範例:
markdown theme={null}
Use the BigQuery:bigquery_schema tool to retrieve table schemas.
Use the GitHub:create_issue tool to create issues.
其中:
BigQuery 與 GitHub 是 MCP server 名稱bigquery_schema 與 create_issue 是這些 server 內的工具名稱沒有 server 前綴時,代理可能找不到工具,特別是在有多個 MCP server 可用時。
不要假設套件已可用:
````markdown theme={null} Bad example: Assumes installation: "Use the pdf library to process the file."
Good example: Explicit about dependencies:
"Install required package: pip install pypdf
Then use it:
python
from pypdf import PdfReader
reader = PdfReader("file.pdf")"
````
SKILL.md 的 frontmatter 需要 name(最多 64 字元)與 description(最多 1024 字元)欄位。完整的結構細節請見技能總覽。
讓 SKILL.md 本體保持在 500 行以內以獲得最佳效能。如果你的內容超過這個數字,用先前描述的漸進揭露模式把它拆到獨立檔案。架構細節請見技能總覽。
分享技能之前,驗證: