在 SQL Server Management Studio 中使用 GitHub Copilot 來運用代理技能

代理技能是可重複使用的指令集,指示 GitHub Copilot 如何執行特定任務。 每個技能都是你定義一次的 markdown 檔案,節省時間並確保整個工作流程的一致性。 把技能視為操作手冊,而不是一個巨大的提示詞。 當你使用 Agent 模式(預覽) 時,Copilot 會根據你的需求自動發現並套用相關技能。

備註

SQL Server Management Studio(SSMS)中的 GitHub Copilot 代理模式目前處於預覽階段。

與自訂 指令設定每個回應的一般偏好不同,技能提供針對特定任務的專屬指引,任何客服都能發現並運用。 定義一個技能一次,它會持續適用於各場次和整個團隊。

先決條件

特工技能的運作方式

使用 Agent 模式時,Copilot 會針對你的存放庫和使用者設定檔,掃描已知技能所在的位置。 如果某項技能描述符合你請求的意圖,Copilot 會啟動該技能並套用指示作為額外上下文。 當技能啟動時,它的名字會出現在聊天室裡,讓你知道它正在被應用。

Copilot 會根據每個技能前置中繼資料中的 description 欄位,決定要啟用哪些技能。 清晰且關鍵字豐富的描述有助於 Copilot 判斷某項技能何時相關。

技能位置

Copilot 從以下地點發現技能:

Scope Paths 詳細資料
工作空間 (與您的團隊共享) .github/skills/.claude/skills/.agents/skills/ 儲存在你的儲存庫根目錄中。 致力於原始碼控制,確保所有團隊成員都能獲得相同的技能。
個人 (僅限個人資料) ~/.copilot/skills/~/.claude/skills/~/.agents/skills/ 適用於你所有的專案。 尚未提交至任何存放庫。

工作區技能的優先順序高於專案特定慣例。 個人技能對於可在不同專案間沿用的工作流程和偏好設定很有幫助。

創造一項技能

你可以在 SSMS 的 技能 面板建立技能,或在檔案系統中手動建立。

從技能面板創建技能

  1. 在Copilot Chat視窗中,選擇 Tools 圖示。
  2. 選擇 技能 面板。
  3. 在技能面板中,選擇按鈕 +
  4. 選擇範圍:儲存在儲存庫中的工作區技能,或儲存在使用者設定檔中的個人技能。
  5. 輸入技能名稱。 名稱成為目錄名稱,且必須使用小寫字母、數字和連字號。
  6. SSMS 會在新的技能目錄中產生一個 SKILL.md 範本。 編輯範本,並將你的指示加入檔案。

手動建立技能

  1. 在適當的位置建立技能目錄。 若是工作區技能,請在儲存庫的根目錄建立 .github/skills/
  2. 為你的技能建立一個子目錄。 每個技能必須有自己的目錄。 例如: .github/skills/tsql-style-guide/
  3. 在技能目錄裡建立一個 SKILL.md 檔案。
  4. 可選擇性地新增支援檔案,如腳本、參考文件或範例輸出。

技能目錄結構

your-repo/
└── .github/
    └── skills/
        └── index-verification/
        │   ├── SKILL.md          # Required: metadata and instructions
        │   └── references/       # Optional: supplementary documentation
        └── agent-job-failure-triage/
            ├── SKILL.md
            └── examples/         # Optional: example scripts

SKILL.md 格式

每個 SKILL.md 檔案必須包含 YAML 前置內容,並附有 Markdown 指令。 前置內容提供了 Copilot 用來發現並啟動該技能的元資料。

前置物性質

Property Required Description
name Yes 只限小寫字母、數字和連字號。 必須與父目錄名稱相符。 最多64字元。
description Yes 描述該技能的作用以及何時使用。 最多1,024字元。 加入具體關鍵字,以判斷該技能是否相關。
license No 授權名稱或隨技能附帶的授權檔案參照。
compatibility No 環境需求,例如預期產品或所需系統能力。
metadata No 用於其他中繼資料的任意鍵值對。
allowed-tools No 以空格分隔的工具名稱清單,為該技能預先核准可使用的工具。

從技能面板管理技能

在Copilot Chat視窗中選擇Tools圖示,開啟Skills面板。 面板會顯示 Copilot 在你當前遊戲中發現的每一項技能。

從面板中,你可以:

  • 編輯:從 ... 選單直接在編輯器中開啟任何技能的 SKILL.md 檔案。
  • 開啟檔案位置:跳到磁碟上的技能目錄。
  • 搜尋:依名稱或關鍵字篩選技能。

面板還會顯示技能配置錯誤的診斷,讓你能快速識別並修正問題。

撰寫有效技能的技巧

  • 保持 SKILL.md 簡潔:目標是線條在300行以內。 將詳細參考資料移至相關子目錄的獨立檔案。
  • 寫出關鍵字豐富的描述:Copilot 使用 description 來決定何時啟動該技能。 包含該技能適用的具體任務、物件與情境。
  • 對於程序,請使用編號步驟:相較於連續敘述,逐步指示更容易讓模型遵循。
  • 包含預期輸出的範例:展示範例程式碼、表格格式或註解區塊,讓模型知道「完成」的樣貌。
  • 設定明確的限制:告訴技能 不能 做什麼。 例如,「不建議在沒有先報告寫入量的情況下,刪除超過 1000 萬列的資料表上的索引。」
  • 參考輔助資料:將相關內容與腳本儲存在檔案中references\scripts\examples\並指向技能中的特定內容。

SQL 技能範例

以下範例展示了如何撰寫常見 SQL Server 任務的技能。 把它們當作起點,並調整以符合你團隊的慣例。

索引驗證

建議新索引前,請先檢視現有索引,以避免重複。

---
name: index-verification
description: Use when an index recommendation has been generated and must be validated before implementation. Verifies workload benefit, redundancy, write overhead, storage impact, and existing index coverage.
---

# Index Verification

## Use this skill when

- A missing index recommendation exists
- An agent generated an index recommendation
- Query tuning suggests adding an index
- A user asks whether an index should be created

## Never assume

- Missing index DMVs are recommendations, not requirements.
- Do not recommend index creation until validation is complete.

## Verification Checklist

### 1. Check Existing Indexes

Determine whether:

- An equivalent index already exists
- A wider index already covers the workload
- Included columns already satisfy the query
- The recommendation duplicates another recommendation

### 2. Estimate Read Benefit

Evaluate:

- Query execution frequency
- Current execution cost
- Expected seek/selectivity improvement
- Number of affected queries

### 3. Evaluate Write Cost

Determine:

- Insert impact
- Update impact
- Delete impact
- Additional maintenance cost

### 4. Evaluate Storage Impact

Estimate:

- Index size on disk
- Memory pressure
- Replication impact

### 5. Make Recommendation

Return one of:

- Create index
- Modify existing index
- Consolidate with existing recommendation
- Reject recommendation

## Avoid

- Blindly trusting missing-index DMVs
- Creating overlapping indexes
- Recommending indexes for one-off queries
- Ignoring write-heavy workloads

## Output Format

Format output as a table: index name, columns, type, and recommendation (create / modify / consolidate / reject).

代理程式作業失敗分級處理

分析失敗的 SQL Agent 工作歷史,並提出解決根本問題的建議。

---
name: agent-job-failure-triage
description: Use when an automated job, workflow, maintenance task, or agent execution fails. Determines root cause and appropriate remediation while avoiding unsafe recovery actions.
---
# Agent Job Failure Triage

## Objective

Identify root cause before attempting remediation.

## First Rule

Never retry repeatedly without understanding why the job failed.

## Investigation Order

### 1. Collect Failure Details

Gather:

- Job name
- Error message
- Start time
- End time
- Retry history

### 2. Classify Failure

Determine whether failure is:

- Resource-related
- Permission-related
- Configuration-related
- Data-related
- Dependency-related
- Other or unknown

### 3. Check Recent Changes

Investigate:

- Deployments
- Configuration changes
- Schema changes
- Security changes
- Infrastructure changes

### 4. Determine Blast Radius

Identify:

- Data modified by job
- Schema modified by job
- Affected users or departments
- Downstream jobs
- SLA impact
- Data correctness risk

## Safe Actions

- Collect logs
- Validate dependencies
- Escalate when root cause is unknown

## Unsafe Actions

- Retry job
- Disable job
- Force-completing jobs
- Disabling validation checks
- Modifying production data to "make it pass"
- Restarting the SQL Agent service