在使用人工智能时,上下文至关重要。每个代码库都有自己的“家规”:组件如何构建、运行哪些脚本,以及适用于不同框架和文件类型的规范有哪些。
Copilot 可以帮助你在整个项目中进行修改,但当它了解这些规则时,效果最佳。许多此类知识可以存储在仓库内部,因此 Copilot 可以自动获取这些信息,而不需要你在每次开始新任务时都重复解释相同的标准、脚本和工作流。
在本系列的 GitHub Copilot 初学者指南这一期中,我们将探讨四种定制 Copilot 与你的项目协作方式的方法:
自定义指令(Custom instructions)传达 Copilot 应遵循的规范。
智能体技能包(Agent skills package)封装可重复执行的流程。
自定义智能体(Custom agents)为大型任务提供专业指导。
模型上下文协议(MCP)服务器将 Copilot 连接到外部工具和数据源,扩展其功能范围。
让我们来看看每一项是如何工作的,以及它们如何协同工作。
从自定义指令开始
假设你要求 Copilot 向应用程序添加自定义页面大小。做出更改只是工作的一部分。新代码也应遵循团队已使用的模式。
仓库级自定义指令为 Copilot 提供了这种基础上下文。你可以添加一个 .github/copilot-instructions.md 文件,以定义适用于整个仓库的指导原则,例如你首选的架构、命名规范,或者对测试和验证的期望。
你还可以在 .github/instructions 内部创建路径特定的指令文件。这些文件使用 applyTo 字段来告知 Copilot 何时适用这些指导原则。
当 Copilot 处理匹配的文件时,它可以同时使用仓库级指令和更具体的指导。这让你可以将广泛适用的规则集中在一处,而无需将所有文件类型都强行纳入同一模式。
将可重复的流程打包为智能体技能
自定义指令适用于那些应影响许多任务的标准。但是,有些指导原则仅在 Copilot 执行特定流程时才重要,例如运行质量检查、准备发布版本或调试失败的工作流。
这正是智能体技能发挥作用的地方。技能是一个文件夹,包含指令以及可选的脚本和其他资源,当它们相关时,Copilot 可以加载这些内容。项目级技能可以存放在 .github/skills 中,每个技能位于其自己的子文件夹内。
例如,.github/skills/quality-checks 文件夹可以包含一个 SKILL.md 文件,其中说明:
Copilot 何时应使用该技能。
哪些脚本运行项目的测试和代码检查(linting)。
每个脚本检查的内容。
如何排查常见故障。
SKILL.md 中的描述有助于 Copilot 确定何时适用该技能。在更新界面后,Copilot 可以加载 quality-checks 技能,并遵循项目既定的测试和代码检查流程,而不是猜测要运行哪些命令。
使用自定义智能体进行更广泛、专业化的工作
有些任务比单一流程更复杂。例如,无障碍审查可能需要 Copilot 跨多个文件检查组件、模板、样式和交互。
自定义智能体让你可以为这类工作创建 Copilot 的专业版本。仓库级智能体配置文件位于 .github/agents,可以定义智能体的目的、指令、工具以及相关的项目上下文。
当重复性的工作类型受益于专用角色或视角时,尤其是当任务可能跨越多个文件并依赖多种工具或上下文来源时,请使用自定义智能体。
指令、技能和智能体帮助 Copilot 理解如何在你的项目中工作。MCP 服务器扩展了它在仓库之外可以访问和执行的操作范围。
MCP 服务器将 Copilot 连接到外部工具、数据源和服务。文档服务器可以让它访问框架指导,而像 Playwright 这样的服务器则可以让它在浏览器中打开并与你的应用程序进行交互。
你可以在 Copilot 应用中浏览可用的 MCP 服务器,或添加自定义服务器。配置好 Playwright 后,你可以发出如下指令:使用 Playwright MCP 服务器手动测试功能。
随后,Copilot 可以利用 Playwright 在浏览器中打开应用程序并进行交互,其操作方式与你手动操作类似。这使得它不仅能够验证代码是否通过自动化检查,还能确认更新后的界面是否符合预期行为。
选择合适的自定义类型
这些自定义配置解决不同的问题,但当它们结合使用时,效用会显著提升:
自定义指令(Custom instructions)定义了 Copilot 在仓库范围内或针对特定文件时应遵循的规范。
智能体技能包(Agent skills package)包含了 Copilot 在相关场景下可加载的可重复操作流程。
自定义智能体(Custom agents)为更广泛的任务提供专注的专业知识和指导。
MCP 服务器将 Copilot 与外部工具、服务和数据源连接起来,扩展了 Copilot 的能力范围。
随身携带这些要点
为 Copilot 提供有用的项目上下文,始于以下四个问题:
我反复解释的项目规范是什么?
我重复执行的多步流程是什么?
哪一项复杂任务适合由专用的自定义智能体来处理?
Copilot 需要哪些外部工具或数据源?
不确定从何入手?社区已通过 Awesome Copilot 分享了现成的指令、技能、智能体等资源。找到能解决你已有重复工作流的资源,审查其内容,并将其适配到你仓库的工具和标准中。
从小处着手:选择一项你反复解释的规范,将其添加到 .github/copilot-instructions.md 文件中,然后观察 Copilot 如何在你的下一个任务中应用它。
作者
GitHub 高级开发者倡导者
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
首次收录 · 2026-10-13 · 9.74 分