官方更新 GitHub Blog AI/ML Mon, 12 Oct 2026 正文 ok 877 words

GitHub Copilot 初学者应用指南:如何让 Copilot 了解你的代码库

英文标题:GitHub Copilot app for Beginners: How to teach Copilot about your codebase

GitHub 介绍了四种让 Copilot 更好理解项目上下文的方式:自定义指令、Agent 技能、自定义 Agent 和模型上下文协议(MCP)服务器。开发者可将代码规范、测试流程和专项任务指导保存在仓库中,减少每次任务中重复说明上下文的需要。MCP 服务器还能将 Copilot 连接到 Playwright 等外部工具,使其能够在浏览器中手动验证应用功能。这些能力可组合使用,帮助团队让 AI 编码代理更贴合既有工程规范、工作流和工具链。
打开原文相关 6 · 机会 5
media75.6 KB media30.1 KB media84.8 KB media37.8 KB media60.5 KB media34.0 KB media127.1 KB media52.6 KB media77.9 KB media33.9 KB media70.2 KB media31.8 KB media84.0 KB media37.3 KB media214.6 KB media143.5 KB media5.1 KB media19.8 KB media127.1 KB media16.8 KB

中文

在使用 AI 时,上下文至关重要。每个代码库都有自己的内部规则:组件如何组织、应运行哪些脚本,以及不同框架和文件类型适用哪些约定。

Copilot 可以帮助你在整个项目中进行修改,但当它同样了解这些规则时,效果会更好。其中大量知识都可以保存在仓库内部,让 Copilot 自动获取,而不必在每次开始新任务时重复解释相同的标准、脚本和工作流。

在本期 GitHub Copilot 初学者应用系列中,我们将介绍四种定制 Copilot 与项目协作方式的方法:

  • 自定义指令用于传达 Copilot 应遵循的约定。
  • Agent 技能可将可重复执行的流程打包。
  • 自定义 Agent 为更大型的任务提供专业化指导。
  • 模型上下文协议(MCP)服务器可将 Copilot 连接到外部工具和数据源,扩展其能力。

下面将分别介绍它们的工作方式,以及如何将它们结合使用。

从自定义指令开始

假设你要求 Copilot 为应用程序添加自定义页面尺寸。完成修改只是工作的一部分,新代码还应遵循团队已经在使用的模式。

仓库自定义指令为 Copilot 提供这类基础上下文。添加 .github/copilot-instructions.md 文件,即可定义适用于整个仓库的指导原则,例如首选架构、命名规范,或对测试和验证的要求。

你也可以在 .github/instructions 中创建路径特定的指令文件。这些文件使用 applyTo 字段告知 Copilot 何时应采用相关指导。

当 Copilot 处理匹配的文件时,它可以同时使用全仓库指令和更具体的指导。这使你能够将通用规则集中保存在一个位置,而不必强迫所有文件类型都遵循同一种模式。

将可重复流程打包为 Agent 技能

自定义指令适合用于应影响许多任务的标准。但有些指导仅在 Copilot 执行特定流程时才有意义,例如运行质量检查、准备发布版本或调试失败的工作流。

这正是 Agent 技能的用武之地。技能是一个文件夹,包含指令,以及可选的脚本和其他资源;Copilot 可以在这些内容相关时加载它们。项目级技能可存放在 .github/skills 中,每项技能位于各自的子文件夹内。

例如,.github/skills/quality-checks 文件夹可包含一个 SKILL.md 文件,说明:

  • Copilot 应在何时使用该技能。
  • 哪些脚本可运行项目的测试和 lint 检查。
  • 每个脚本检查什么内容。
  • 如何排查常见故障。

SKILL.md 中的描述可帮助 Copilot 判断该技能何时适用。更新界面后,Copilot 可以加载 quality-checks 技能,并遵循项目既定的测试和 lint 流程,而不是猜测应该运行哪些命令。

使用自定义 Agent 处理更广泛的专业化工作

有些任务的范围比单一流程更大。例如,无障碍审查可能要求 Copilot 检查多个文件中的组件、模板、样式和交互。

自定义 Agent让你能够针对这类工作创建专业化版本的 Copilot。仓库级 Agent 配置文件位于 .github/agents 中,可定义 Agent 的用途、指令、工具和相关项目上下文。

当一种重复性工作需要专门的角色或视角时,应使用自定义 Agent,尤其是在任务可能跨越多个文件,并需要调用多种工具或上下文来源的情况下。

指令、技能和 Agent 可帮助 Copilot 理解如何在你的项目中开展工作。MCP 服务器则扩展了它在仓库之外可访问和可执行的能力。

MCP 服务器可将 Copilot 连接到外部工具、数据源和服务。文档服务器可以使其访问框架指南,而 Playwright 等服务器则可以让它在浏览器中打开并与应用程序交互。

你可以在 Copilot 应用中浏览可用的 MCP 服务器,也可以添加自定义服务器。配置 Playwright 后,你可以提出如下请求:使用 Playwright MCP 服务器手动测试功能。

随后,Copilot 可以使用 Playwright 在浏览器中打开应用程序,并像你一样与其交互。这使它不仅能够验证代码是否通过自动化检查,还能验证更新后的界面是否按预期运行。

选择合适的定制类型

这些定制方式解决的问题各不相同,但将它们结合使用会更有价值:

  • 自定义指令定义 Copilot 应在整个仓库或特定文件中遵循的约定。
  • Agent 技能将 Copilot 可在相关时加载的可重复流程打包。
  • 自定义 Agent为更广泛的任务提供聚焦的专业知识和指导。
  • MCP 服务器将 Copilot 连接到外部工具、服务和数据源,扩展 Copilot 的能力。

记住这些要点

为 Copilot 提供有用的项目上下文,可以先从四个问题开始:

  • 我不断重复解释的是哪项项目约定?
  • 我反复执行的是哪项多步骤流程?
  • 哪项复杂任务能够从专用自定义 Agent 中获益?
  • Copilot 需要哪种外部工具或信息来源?

不确定从哪里开始?社区已通过 Awesome Copilot 分享了现成的指令、技能、Agent 等资源。找到一项能够解决你已在重复执行的工作流的资源,查看其包含的内容,然后根据你的仓库工具和标准进行调整。

从小处开始:选择一项你不断重复解释的约定,将其添加到 .github/copilot-instructions.md,然后观察 Copilot 如何在下一项任务中应用它。

作者

GitHub 高级开发者倡导者

English / 原文

Context matters when you’re working with AI. Every codebase has its own house rules: how components are structured, which scripts to run, and which conventions apply to different frameworks and file types.

Copilot can help you make changes across a project, but it works best when it knows those rules, too. Much of that knowledge can live inside the repository, so Copilot can pick it up automatically instead of requiring you to explain the same standards, scripts, and workflows every time you start a new task.

In this installment of our GitHub Copilot app for Beginners series, we’ll look at four ways to tailor how Copilot works with your project:

  • Custom instructions communicate the conventions Copilot should follow.
  • Agent skills package repeatable procedures.
  • Custom agents bring specialized guidance to larger tasks.
  • Model Context Protocol (MCP) servers connect Copilot to external tools and data sources, expanding what it can do.

Let’s look at how each one works and how they can work together.

Start with custom instructions

Suppose you ask Copilot to add a custom page size to an application. Making the change is only part of the job. The new code should also follow the patterns your team already uses.

Repository custom instructions give Copilot that baseline context. Add a .github/copilot-instructions.md file to define guidance that applies across the repository, such as your preferred architecture, naming conventions, or expectations for testing and validation.

You can also create path-specific instruction files inside .github/instructions. These files use an applyTo field to tell Copilot when the guidance is relevant.

When Copilot works on a matching file, it can use both the repository-wide instructions and the more specific guidance. That lets you keep the broad rules in one place without forcing every file type into the same mold.

Package repeatable procedures as agent skills

Custom instructions are useful for standards that should shape many tasks. But some guidance only matters when Copilot is performing a particular procedure, such as running quality checks, preparing a release, or debugging a failed workflow.

That’s where agent skills come in. A skill is a folder containing instructions and, optionally, scripts and other resources that Copilot can load when they’re relevant. Project-level skills can live in .github/skills, with each skill in its own subfolder.

For example, a .github/skills/quality-checks folder could contain a SKILL.md file that explains:

  • When Copilot should use the skill.
  • Which scripts run the project’s tests and linting.
  • What each script checks.
  • How to troubleshoot common failures.

The description in SKILL.md helps Copilot determine when the skill applies. After updating the interface, Copilot can load the quality-checks skill and follow the project’s established process for testing and linting instead of guessing which commands to run.

Use a custom agent for broader, specialized work

Some tasks are larger than a single procedure. An accessibility review, for example, may require Copilot to inspect components, templates, styles, and interactions across multiple files.

Custom agents let you create specialized versions of Copilot for work like this. A repository-level agent profile lives in .github/agents and can define the agent’s purpose, instructions, tools, and relevant project context.

Use a custom agent when a recurring type of work benefits from a dedicated role or perspective, especially when the task may span multiple files and draw on several tools or sources of context.

Instructions, skills, and agents help Copilot understand how to work within your project. MCP servers expand what it can access and do beyond the repository.

MCP servers connect Copilot to external tools, data sources, and services. A documentation server can give it access to framework guidance, while a server such as Playwright can let it open and interact with your application in a browser.

You can browse available MCP servers in the Copilot app or add a custom one. Once Playwright is configured, you can ask: Use the Playwright MCP server to test the functionality manually.

Copilot can then use Playwright to open the application in a browser and interact with it much as you would. That gives it a way to verify not only that the code passes automated checks, but also that the updated interface behaves as expected.

Choose the right type of customizations

These customizations solve different problems, but they become more useful when you combine them:

  • Custom instructions define the conventions Copilot should follow across the repository or for particular files.
  • Agent skills package repeatable procedures that Copilot can load when they’re relevant.
  • Custom agents provide focused expertise and guidance for broader tasks.
  • MCP servers connect Copilot to external tools, services, and data sources, expanding what Copilot can do.

Take this with you

Giving Copilot useful project context starts with four questions:

  • What project convention do I keep explaining?
  • What multi-step procedure do I repeat?
  • What complex task could benefit from a dedicated custom agent?
  • What outside tool or source does Copilot need?

Not sure where to begin? The community has shared ready-made instructions, skills, agents, and more through Awesome Copilot. Find one that addresses a workflow you already repeat, review what it contains, and adapt it to your repository’s tools and standards.

Start small: choose one convention you keep explaining, add it to .github/copilot-instructions.md, and see how Copilot applies it to your next task.

Written by

Senior Developer Advocate, GitHub