在 SQL Server Management Studio 中将代理技能与GitHub Copilot配合使用

代理技能是可重用的指令集,指示GitHub Copilot如何执行特定任务。 每个技能都是一个 markdown 文件,用于定义一次、节省时间并确保工作流中的一致行为。 把技能看作运行手册,而不是单个大型提示词。 使用 Agent 模式(预览)时,Copilot会根据要询问的内容自动发现并应用相关技能。

注释

SQL Server Management Studio(SSMS)中的 GitHub Copilot 代理模式目前处于预览状态。

与设置每个响应的常规首选项的 自定义说明不同,技能提供了特定于任务的集中指导,任何代理都可以发现和使用。 某项技能只需定义一次,即可在不同会话之间以及整个团队中统一应用。

先决条件

代理技能的工作原理

使用代理模式时,Copilot 会扫描你的代码存储库和用户配置文件中的已知技能位置。 如果技能的说明与请求的意图匹配,Copilot激活该技能,并将其说明作为额外的上下文应用。 当技能处于活动状态时,其名称将显示在聊天中,以便你知道它正在应用。

Copilot 根据每个技能前置元数据中的 description 字段来决定激活哪些技能。 清晰且包含丰富关键词的描述有助于 Copilot 识别某项技能何时适用。

技能位置

Copilot 从以下位置中发现技能:

Scope 路径 详细信息
工作区 (与团队共享) .github/skills/.claude/skills/.agents/skills/ 存储在存储库根目录中。 致力于源代码管理,以便所有团队成员获得相同的技能。
个人 (仅限个人资料) ~/.copilot/skills/~/.claude/skills/~/.agents/skills/ 适用于所有项目。 未提交到任何存储库。

工作区技能优先于特定于项目的约定。 个人技能对于可跨项目沿用的工作流和偏好设置非常有用。

创建技能

可以从 SSMS 中的 技能 面板或在文件系统中手动创建技能。

从“技能”面板创建技能

  1. 在Copilot 对话助手窗口中,选择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 说明。 frontmatter 提供了 Copilot 用于发现和激活技能的元数据。

Frontmatter 属性

财产 必需 Description
name 是的 仅小写字母、数字和连字符。 必须与父目录名称匹配。 最多 64 个字符。
description 是的 描述技能的作用以及何时使用它。 最多 1,024 个字符。 包含能够表明该技能在何种情况下适用的特定关键词。
license No 许可证名称或对与技能捆绑的许可证文件的引用。
compatibility No 环境要求,例如预期的产品或所需的系统功能。
metadata No 用于其他元数据的任意键值对。
allowed-tools No 该技能已预先获准使用的工具名称列表,以空格分隔。

从“技能”面板管理技能

选择Copilot 对话助手窗口中的 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 代理作业的历史记录,并提出建议以解决根本问题。

---
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