
如果 Copilot 能自動套用你們團隊的最佳實踐,而不需要你每次都重新說明,會怎麼樣?
在本章中,你將學習 Agent 技能:這是一種指令資料夾,當 Copilot 偵測到與你的任務相關時會自動載入。Agent 會改變 Copilot 思考的方式,而技能則教 Copilot 完成任務的具體方法。你將建立一個安全稽核技能,讓 Copilot 在你詢問安全相關問題時自動套用,打造團隊標準的審查規範,確保程式碼品質一致,並學會技能如何在 Copilot CLI、VS Code 及 GitHub Copilot 雲端 agent 中運作。
完成本章後,你將能夠:
⏱️ 預估時間:約 55 分鐘(閱讀 20 分鐘 + 實作 35 分鐘)
一般的電鑽很有用,但專用的配件讓它更強大。

技能的運作方式也一樣。就像根據不同工作更換鑽頭一樣,你可以為 Copilot 加入不同任務的技能:
| 技能配件 | 用途 |
|---|---|
commit |
產生一致的提交訊息 |
security-audit |
檢查 OWASP 漏洞 |
generate-tests |
建立完整的 pytest 測試 |
code-checklist |
套用團隊程式碼品質標準 |
技能是專用配件,能擴充 Copilot 的能力

了解什麼是技能、為什麼重要,以及它們與 Agent 和 MCP 的差異。
copilot
> /skills list
這會顯示 Copilot 能找到的所有技能,包括 CLI 內建的內建技能、專案資料夾和個人資料夾中的技能。
💡 內建技能:Copilot CLI 預設就有內建技能。例如,
customizing-copilot-cloud-agents-environment技能提供自訂 Copilot 雲端 agent 環境的指南。這些技能無需額外建立或安裝即可使用。執行/skills list查看有哪些可用技能。
看看實際的技能檔案: 參考我們提供的 code-checklist SKILL.md 範例。它就是 YAML frontmatter 加上 markdown 指令。
Agent 技能是一種資料夾,內含指令、腳本與資源,當與你的任務相關時 Copilot 會自動載入。Copilot 會讀取你的提示詞,檢查是否有技能符合,並自動套用相關指令。
copilot
> Check books.py against our quality checklist
# Copilot 偵測到這符合你的 "code-checklist" 技能
# 並自動套用 Python 品質檢查清單
> Generate tests for the BookCollection class
# Copilot 載入你的 "pytest-gen" 技能
# 並套用你偏好的測試結構
> What are the code quality issues in this file?
# Copilot 載入你的 "code-checklist" 技能
# 並依據團隊標準檢查
💡 重點:技能會根據你的提示詞是否符合技能描述自動觸發。只要自然提問,Copilot 會在背後自動套用相關技能。你也可以直接呼叫技能,下一節會介紹。
🧰 現成範本:參考 .github/skills 資料夾,裡面有可直接複製貼上的簡易技能範例。
雖然自動觸發是技能的主要運作方式,你也可以用 slash 指令直接呼叫技能:
> /generate-tests Create tests for the user authentication module
> /code-checklist Check books.py for code quality issues
> /security-audit Check the API endpoints for vulnerabilities
這讓你在需要時能明確指定要用哪個技能。
你可以在同一則訊息中呼叫多個技能,slash 指令可以出現在提示詞的任何位置——不一定要在開頭。這很適合一次做兩種檢查:
> Check @samples/book-app-project/book_app.py with /code-checklist and also run /generate-tests for it
> Review the auth module /security-audit then /code-checklist the result
Copilot 會在同一回應中套用所有指定的技能,省去你多次分開詢問的麻煩。
💡 小技巧:slash 指令可以放在句子的任何地方,依你覺得自然的位置即可。可以在開頭、中間或結尾。
📝 技能 vs Agent 呼叫方式:不要混淆技能與 Agent 的呼叫方式:
- 技能:
/skill-name <prompt>,例如/code-checklist Check this file- Agent:
/agent(從清單選擇)或copilot --agent <name>(命令列)
如果你同時有同名的技能和 Agent(例如 “code-reviewer”),輸入
/code-reviewer會呼叫技能,而不是 Agent。
你可以直接問 Copilot:
> What skills did you use for that response?
> What skills do you have available for security reviews?
技能只是 GitHub Copilot 擴充模型的一部分。以下是它們與 Agent、MCP 伺服器的比較。
不用急著了解 MCP。我們會在第 06 章詳細介紹。這裡先讓你了解技能在整體架構中的定位。

| 功能 | 作用 | 適用時機 |
|---|---|---|
| Agent | 改變 AI 的思考方式 | 需要跨多種任務的專業知識時 |
| 技能 | 提供特定任務指令 | 具體、可重複且有詳細步驟的任務 |
| MCP | 連接外部服務 | 需要即時 API 資料時 |
Agent 適合廣泛專業知識,技能適合具體任務指令,MCP 則用於外部資料。Agent 在對話中可以同時使用一個或多個技能。例如,當你請 Agent 檢查程式碼時,它可能會自動套用 security-audit 技能和 code-checklist 技能。
📚 深入了解:完整技能格式與最佳實踐請參考官方文件 About Agent Skills。
在學習如何建立技能之前,先看看為什麼值得學。當你看到一致性的提升後,「怎麼做」就會更有意義。
每次程式碼審查,你可能都會漏掉某些項目:
copilot
> Review this code for issues
# 一般性的審查——可能漏掉你們團隊特有的重點
或者你每次都要打一長串提示:
> Review this code checking for bare except clauses, missing type hints,
> mutable default arguments, missing context managers for file I/O,
> functions over 50 lines, print statements in production code...
耗時:30 秒以上。一致性:取決於記憶力。
安裝 code-checklist 技能後,只要自然提問:
copilot
> Check the book collection code for quality issues
背後發生的事:
code-checklist 技能符合
只要自然提問,Copilot 會自動對應並套用正確技能。
輸出範例:
## Code Checklist: books.py
### Code Quality
- [PASS] All functions have type hints
- [PASS] No bare except clauses
- [PASS] No mutable default arguments
- [PASS] Context managers used for file I/O
- [PASS] Functions are under 50 lines
- [PASS] Variable and function names follow PEP 8
### Input Validation
- [FAIL] User input is not validated - add_book() accepts any year value
- [FAIL] Edge cases not fully handled - empty strings accepted for title/author
- [PASS] Error messages are clear and helpful
### Testing
- [FAIL] No corresponding pytest tests found
### Summary
3 items need attention before merge
差異:團隊標準每次都自動套用,不用再手動輸入。
想像你的團隊有 10 點 PR 檢查清單。沒有技能時,每個開發者都要記住這 10 點,總有人會漏掉。有了 pr-review 技能,整個團隊都能得到一致的審查:
copilot
> Can you review this PR?
Copilot 會自動載入你們團隊的 pr-review 技能,檢查所有 10 點:
PR Review: feature/user-auth
## Security ✅
- No hardcoded secrets
- Input validation present
- No bare except clauses
## Code Quality ⚠️
- [WARN] print statement on line 45 - remove before merge
- [WARN] TODO on line 78 missing issue reference
- [WARN] Missing type hints on public functions
## Testing ✅
- New tests added
- Edge cases covered
## Documentation ❌
- [FAIL] Breaking change not documented in CHANGELOG
- [FAIL] API changes need OpenAPI spec update
威力:每個團隊成員都能自動套用相同標準。新進人員不用背清單,技能會自動處理。

從 SKILL.md 檔案開始打造自己的技能。
技能儲存在 .github/skills/(專案專屬)或 ~/.copilot/skills/(使用者層級)。
Copilot 會自動掃描這些位置尋找技能:
| 位置 | 範圍 |
|---|---|
.github/skills/ |
專案專屬(透過 git 與團隊共用) |
~/.copilot/skills/ |
使用者專屬(你的個人技能) |
每個技能都放在自己的資料夾,內含一個 SKILL.md 檔案。你也可以選擇加入腳本、範例或其他資源:
.github/skills/
└── my-skill/
├── SKILL.md # 必要:技能定義與指令
├── examples/ # 選用:Copilot 可參考的範例檔案
│ └── sample.py
└── scripts/ # 選用:技能可用的腳本
└── validate.sh
💡 小技巧:資料夾名稱應與 SKILL.md frontmatter 的
name欄位一致(小寫並用連字號)。
技能使用簡單的 markdown 格式,搭配 YAML frontmatter:
---
name: code-checklist
description: Comprehensive code quality checklist with security, performance, and maintainability checks
license: MIT
---
# Code Checklist
When checking code, look for:
## Security
- SQL injection vulnerabilities
- XSS vulnerabilities
- Authentication/authorization issues
- Sensitive data exposure
## Performance
- N+1 query problems (running one query per item instead of one query for all items)
- Unnecessary loops or computations
- Memory leaks
- Blocking operations
## Maintainability
- Function length (flag functions > 50 lines)
- Code duplication
- Missing error handling
- Unclear naming
## Output Format
Provide issues as a numbered list with severity:
- [CRITICAL] - Must fix before merge
- [HIGH] - Should fix before merge
- [MEDIUM] - Should address soon
- [LOW] - Nice to have
YAML 屬性說明:
| 屬性 | 必填 | 說明 |
|---|---|---|
name |
是 | 唯一識別名稱(小寫、空格用連字號) |
description |
是 | 技能用途,以及 Copilot 何時該使用 |
license |
否 | 技能適用的授權條款 |
📖 官方文件:About Agent Skills
讓我們來打造一個檢查 OWASP Top 10 漏洞的安全稽核技能:
# 建立技能資料夾
mkdir -p .github/skills/security-audit
# 建立 SKILL.md 檔案
cat > .github/skills/security-audit/SKILL.md << 'EOF'
---
name: security-audit
description: Security-focused code review checking OWASP (Open Web Application Security Project) Top 10 vulnerabilities
---
# Security Audit
Perform a security audit checking for:
## Injection Vulnerabilities
- SQL injection (string concatenation in queries)
- Command injection (unsanitized shell commands)
- LDAP injection
- XPath injection
## Authentication Issues
- Hardcoded credentials
- Weak password requirements
- Missing rate limiting
- Session management flaws
## Sensitive Data
- Plaintext passwords
- API keys in code
- Logging sensitive information
- Missing encryption
## Access Control
- Missing authorization checks
- Insecure direct object references
- Path traversal vulnerabilities
## Output
For each issue found, provide:
1. File and line number
2. Vulnerability type
3. Severity (CRITICAL/HIGH/MEDIUM/LOW)
4. Recommended fix
EOF
# 測試你的技能(技能會根據提示自動載入)
copilot
> @samples/book-app-project/ Check this code for security vulnerabilities
# Copilot 偵測到 "security vulnerabilities" 符合你的技能
# 並自動套用 OWASP 檢查清單
預期輸出(實際結果會有所不同):
Security Audit: book-app-project
[HIGH] Hardcoded file path (book_app.py, line 12)
File path is hardcoded rather than configurable
Fix: Use environment variable or config file
[MEDIUM] No input validation (book_app.py, line 34)
User input passed directly to function without sanitization
Fix: Add input validation before processing
✅ No SQL injection found
✅ No hardcoded credentials found
SKILL.md 的 description 欄位非常重要!Copilot 就是根據它來決定是否載入你的技能:
---
name: security-audit
description: Use for security reviews, vulnerability scanning,
checking for SQL injection, XSS, authentication issues,
OWASP Top 10 vulnerabilities, and security best practices
---
💡 小技巧:描述中要包含你平常提問時會用到的關鍵字。如果你會說「security review」,那就把「security review」寫進 description。
技能與 Agent 可以搭配運作。Agent 提供專業知識,技能則給出具體指令:
# 啟動 code-reviewer Agent
copilot --agent code-reviewer
> Check the book app for quality issues
# code-reviewer Agent 的專業知識
# 結合 code-checklist 技能的檢查清單
探索已安裝技能、尋找社群技能、並分享你自己的技能。

/skills 指令管理技能使用 /skills 指令管理你已安裝的技能:
| 指令 | 功能說明 |
|---|---|
/skills list |
顯示所有已安裝技能 |
/skills info <name> |
查看特定技能詳細資訊 |
/skills add <name> |
啟用技能(從儲存庫或市集) |
/skills remove <name> |
停用或解除安裝技能 |
/skills reload |
編輯 SKILL.md 後重新載入技能 |
💡 請記住:你不需要每次都「啟用」技能。只要安裝好,當你的提示詞符合描述時,技能就會自動觸發。這些指令是用來管理技能的可用性,不是用來呼叫技能。
copilot
> /skills list
Available skills:
- security-audit: Security-focused code review checking OWASP Top 10
- generate-tests: Generate comprehensive unit tests with edge cases
- code-checklist: Team code quality checklist
...
> /skills info security-audit
Skill: security-audit
Source: Project
Location: .github/skills/security-audit/SKILL.md
Description: Security-focused code review checking OWASP Top 10 vulnerabilities
/skills reload建立或編輯 SKILL.md 檔案後,執行 /skills reload 就能載入變更,無需重啟 Copilot:
# 編輯你的技能檔案
# 然後在 Copilot 中執行:
> /skills reload
Skills reloaded successfully.
💡 補充說明:即使你用
/compact指令壓縮對話歷史,技能依然有效。壓縮後不用重新載入技能。
💡 什麼是外掛? 外掛是可安裝的套件,可以同時包含技能、Agent 和 MCP 伺服器設定。你可以把它們想像成 Copilot CLI 的「應用程式商店」擴充功能。
使用 /plugin 指令可以瀏覽並安裝這些套件:
copilot
> /plugin list
# 顯示已安裝外掛
> /plugin marketplace
# 瀏覽可用外掛
> /plugin install <plugin-name>
# 從市集安裝外掛
要讓本地外掛目錄保持最新,請執行:
copilot plugin marketplace update
外掛可以同時包含多種功能。一個外掛可能包含相關的技能、Agent 和 MCP 伺服器設定,彼此協同運作。
你也可以從社群儲存庫取得現成技能:
從 GitHub 儲存庫安裝技能最簡單的方法是使用 gh skill install 指令(需 GitHub CLI v2.90.0+):
# 瀏覽並互動式選擇 awesome-copilot 的技能
gh skill install github/awesome-copilot
# 或直接安裝特定技能
gh skill install github/awesome-copilot ai-ready
# 安裝到所有專案皆可用(使用者層級)
gh skill install github/awesome-copilot ai-ready --scope user
⚠️ 安裝前請審查:安裝技能前務必閱讀其
SKILL.md。技能會控制 Copilot 的行為,惡意技能可能指示 Copilot 執行有害指令或意外修改程式碼。

動手建立並測試自己的技能,應用你所學的內容。
以下是兩個不同類型的技能範例。請依「建立你的第一個技能」章節的 mkdir + cat 流程操作,或直接複製貼上到正確位置。更多範例可參考 .github/skills。
這個技能確保你的程式碼庫 pytest 結構一致:
mkdir -p .github/skills/pytest-gen
cat > .github/skills/pytest-gen/SKILL.md << 'EOF'
---
name: pytest-gen
description: Generate comprehensive pytest tests with fixtures and edge cases
---
# pytest Test Generation
Generate pytest tests that include:
## Test Structure
- Use pytest conventions (test_ prefix)
- One assertion per test when possible
- Clear test names describing expected behavior
- Use fixtures for setup/teardown
## Coverage
- Happy path scenarios
- Edge cases: None, empty strings, empty lists
- Boundary values
- Error scenarios with pytest.raises()
## Fixtures
- Use @pytest.fixture for reusable test data
- Use tmpdir/tmp_path for file operations
- Mock external dependencies with pytest-mock
## Output
Provide complete, runnable test file with proper imports.
EOF
這個技能可強制團隊 PR 審查標準一致:
mkdir -p .github/skills/pr-review
cat > .github/skills/pr-review/SKILL.md << 'EOF'
---
name: pr-review
description: Team-standard PR review checklist
---
# PR Review
Review code changes against team standards:
## Security Checklist
- [ ] No hardcoded secrets or API keys
- [ ] Input validation on all user data
- [ ] No bare except clauses
- [ ] No sensitive data in logs
## Code Quality
- [ ] Functions under 50 lines
- [ ] No print statements in production code
- [ ] Type hints on public functions
- [ ] Context managers for file I/O
- [ ] No TODOs without issue references
## Testing
- [ ] New code has tests
- [ ] Edge cases covered
- [ ] No skipped tests without explanation
## Documentation
- [ ] API changes documented
- [ ] Breaking changes noted
- [ ] README updated if needed
## Output Format
Provide results as:
- ✅ PASS: Items that look good
- ⚠️ WARN: Items that could be improved
- ❌ FAIL: Items that must be fixed before merge
EOF
quick-review 技能,檢查三項重點:
測試方式:詢問「Do a quick review of books.py」
技能比較:計時自己手動輸入詳細的安全審查提示,再只輸入「Check for security issues in this file」讓 security-audit 技能自動載入。技能幫你省下多少時間?
自我檢查:你能解釋為什麼 description 欄位很重要(因為 Copilot 會根據它決定是否載入技能),就代表你已經理解技能的原理。
上面的範例建立了 pytest-gen 和 pr-review 技能。現在請練習建立一個完全不同類型的技能:根據資料產生格式化輸出的技能。
/skills list。你也可以使用 ls .github/skills/ 查看專案技能,或用 ls ~/.copilot/skills/ 查看個人技能。.github/skills/book-summary/SKILL.md 建立一個 book-summary 技能,用來產生書籍收藏的格式化 markdown 摘要@samples/book-app-project/data.json Summarize the books in this collection/skills list/book-summary Summarize the books in this collection 呼叫它成功標準:你擁有一個可運作的 book-summary 技能,當你詢問書籍收藏時,Copilot 會自動套用它。
commit-message 技能,能以一致格式產生 conventional commit 訊息copilot-skill 標籤分享/skill-name 斜線指令直接呼叫技能.github/skills/ 適合專案/團隊共用,~/.copilot/skills/ 適合個人使用📋 快速參考:完整指令與捷徑請見 GitHub Copilot CLI 指令參考。
技能讓 Copilot 能自動載入指令,擴展其能力。但如果要連接外部服務呢?這時就需要 MCP。
在 第 06 章:MCP 伺服器,你將學到:
| ← 回到第 04 章 | 繼續前往第 06 章 → |