自定义代理允许您针对特定任务定制 Copilot 的专长。欲了解自定义代理的概念概览,请参阅 关于自定义代理。
注意
自定义代理目前在 JetBrains IDE、Eclipse 和 Xcode 中公开预览,且可能会更改。
在 GitHub 仓库中创建自定义代理配置文件
-
在 https://github.com/copilot/agents 上导航到 agents 选项卡。
-
在提示框的下拉菜单中,选择您想要创建自定义代理配置文件的仓库。
注意
组织和企业所有者可以在
.github-private仓库中创建组织级和企业级自定义代理,这些代理可在其组织或企业内的所有仓库中使用。欲了解更多信息,请参阅 准备在企业中使用自定义代理 与 准备在组织中使用自定义代理。 -
可选地,选择要创建代理配置文件的分支。默认是 main 分支。
-
点击,然后点击 创建代理。这将打开一个模板代理配置文件,名为
my-agent.agent.md,位于目标仓库的.github/agents目录中。 -
如果您正在创建组织级或企业级自定义代理,请删除文件路径中的
.github/部分,以将模板移动到根agents目录。 -
编辑文件名(
.agent.md前的文本),选择一个唯一且描述性强的名称,以标识该代理的用途。请注意,文件名只能包含以下字符:.、-、_、a-z、A-Z、0-9。 -
配置代理配置文件,包括名称、描述、工具和提示。有关代理配置文件可以包含哪些内容的更多信息,请参阅 配置代理配置文件。
-
将文件提交到仓库并合并到默认分支。必要时返回 agents 选项卡并刷新页面。现在,当您点击时,您的自定义代理将出现在下拉菜单中提示框中。
在 Visual Studio Code 中创建自定义代理配置文件
- 在 Visual Studio Code 中打开 GitHub Copilot Chat。
- 在聊天视图底部的 agents 下拉列表中,点击 配置自定义代理...,然后点击 创建新的自定义代理。
- 选择应创建代理配置文件的位置
- 工作区:在工作区的
.github/agents文件夹中创建自定义代理配置文件,仅在该工作区内使用。 - 用户配置文件:在当前用户配置文件文件夹中创建自定义代理配置文件,以在所有工作区中使用。
- 工作区:在工作区的
- 为自定义代理输入文件名。这将是 agents 下拉菜单中显示的默认名称。
- 在新创建的
.agent.md文件中配置代理配置文件,包括描述、工具和提示。有关代理配置文件可以包含哪些内容的更多信息,请参阅 配置代理配置文件。- 您可以使用编辑器内的 配置工具... 按钮打开“配置工具”对话框,在其中查看并选择可用工具(包括内置工具和来自 MCP 服务器的工具)。点击 确定 将所选工具添加到代理配置文件中。
- 要设置代理使用的 AI 模型,请添加
model:属性并从自动完成下拉列表中选择您首选的模型。
要更新代理配置文件,请在 agents 下拉列表中选择 配置自定义代理,然后点击列表中的相应代理进行修改。欲了解 VS Code 中自定义代理的更多信息,请参阅 VS Code 中的自定义代理。
在 JetBrains IDE 中创建自定义代理配置文件
- 在 JetBrains IDE 中打开 GitHub Copilot Chat 窗口。
- 在聊天视图底部的 agents 下拉列表中,点击 配置代理...,随后在设置窗口的 “Chat Agents” 部分点击 工作区。
- 为自定义代理输入文件名。这将是 agents 下拉菜单中显示的默认名称。
- 在
.github/agents目录中新建的.agent.md文件中配置代理配置文件,包括描述、工具和提示。有关代理配置文件可以包含哪些内容的更多信息,请参阅 配置代理配置文件。- 您可以使用编辑器内的 配置工具... 按钮打开工具对话框,在其中查看并选择可用工具(包括内置工具和来自 MCP 服务器的工具)。点击 应用 将所选工具添加到代理配置文件中。
- 要设置代理使用的 AI 模型,请添加
model:属性并从自动完成下拉列表中选择您首选的模型。
要更新代理配置文件,请在 agents 下拉列表中选择 配置自定义代理,然后点击要修改的代理旁边的按钮。
在 Eclipse 中创建自定义代理配置文件
- 在 Eclipse 中打开 GitHub Copilot Chat 窗口。
- 在聊天视图底部的 agents 下拉列表中,点击 配置代理...,随后点击 添加...。
- 为自定义代理输入文件名。这将是 agents 下拉菜单中显示的默认名称。
- 在
.github/agents目录中新建的.agent.md文件中配置代理配置文件,包括描述、工具和提示。有关代理配置文件可以包含哪些内容的更多信息,请参阅 配置代理配置文件。- 您可以使用编辑器内的 配置工具... 按钮打开“配置工具”对话框,在其中查看并选择可用工具(包括内置工具和来自 MCP 服务器的工具)。点击 应用 将所选工具添加到代理配置文件中。
- 要设置代理使用的 AI 模型,请添加
model:属性并从自动完成下拉列表中选择您首选的模型。
要更新代理配置文件,请在 agents 下拉列表中选择 配置代理...,然后选中要修改的代理并点击 编辑。
在 Xcode 中创建自定义代理配置文件
- 在 Xcode 中打开 GitHub Copilot Chat 窗口。
- 在聊天视图底部的 agents 下拉列表中,点击 创建代理。
- 为自定义代理输入文件名。这将是 agents 下拉菜单中显示的默认名称。
- 在
.github/agents目录中新建的.agent.md文件中配置代理配置文件,包括描述、工具和提示。有关代理配置文件可以包含哪些内容的更多信息,请参阅 配置代理配置文件。- 您可以在文件编辑器中使用 自定义代理 按钮打开对话框,在其中选择代理使用的 AI 模型、选择可用工具(包括内置工具和 MCP 服务器工具),并配置
handoffs属性以在自定义代理之间切换。点击 应用 将所选选项添加到代理配置文件中。
- 您可以在文件编辑器中使用 自定义代理 按钮打开对话框,在其中选择代理使用的 AI 模型、选择可用工具(包括内置工具和 MCP 服务器工具),并配置
要更新代理配置文件,请在 agents 下拉列表中点击要修改的代理旁边的铅笔图标。
配置代理配置文件
代理配置文件是一个带有 YAML frontmatter 的 Markdown 文件,用于指定自定义代理的名称、描述、可用工具以及 MCP 服务器配置。配置代理配置文件涉及定义代理的身份、能力、工具访问权限和行为指令。
有关 YAML 属性、工具、MCP 服务器设置、工具别名以及自定义代理处理方式的详细配置信息,请参阅 自定义代理配置。
要配置您的代理配置文件
- 可选地,为您的自定义代理编写
name。如果未设置,名称默认取文件名(去除.md或.agent.md后缀)。 - 编写简要的
description(必填),说明您的代理的功能以及其特定的能力或领域专长。 - 在
tools属性中,定义代理可以使用的工具。这是一个工具名称或别名的列表,包含在仓库设置或代理配置文件中配置的 MCP 服务器提供的工具(例如tools: ["read", "edit", "search", "some-mcp-server/tool-1"])。如果省略此属性,代理将拥有所有可用工具的访问权限。请参阅 自定义代理配置 中的 “Tools”。 - 可选地,在
mcp-servers属性中,您可以配置仅对该代理可用的 MCP 服务器,以扩展其功能。请参阅 自定义代理配置 中的 “MCP server configuration details”。 - 如果您在 VS Code、JetBrains IDE、Eclipse 或 Xcode 中创建并使用代理配置文件,还可以使用
model属性来控制代理应使用的 AI 模型。 - 可选地,将
target属性设置为vscode或github-copilot,以仅在特定环境中使用该代理。如果省略此属性,代理将在两种环境中均可用。 - 编写代理的提示。 在 YAML frontmatter 下面的 Markdown 内容中定义代理的行为、专长和指令。提示最长可达 30,000 字符。
示例代理配置文件
以下示例展示了在编写测试或规划项目实现等常见任务中,代理配置文件可能的形式。想获取更多灵感,请参阅定制库中的 自定义代理 示例。您还可以在 awesome-copilot 社区集合中找到更具体的示例。
测试专家
此示例通过省略 tools 属性来启用所有工具。
--- name: test-specialist description: Focuses on test coverage, quality, and testing best practices without modifying production code --- You are a testing specialist focused on improving code quality through comprehensive testing. Your responsibilities: - Analyze existing tests and identify coverage gaps - Write unit tests, integration tests, and end-to-end tests following best practices - Review test quality and suggest improvements for maintainability - Ensure tests are isolated, deterministic, and well-documented - Focus only on test files and avoid modifying production code unless specifically requested Always include clear test descriptions and use appropriate testing patterns for the language and framework.
---
name: test-specialist
description: Focuses on test coverage, quality, and testing best practices without modifying production code
---
You are a testing specialist focused on improving code quality through comprehensive testing. Your responsibilities:
- Analyze existing tests and identify coverage gaps
- Write unit tests, integration tests, and end-to-end tests following best practices
- Review test quality and suggest improvements for maintainability
- Ensure tests are isolated, deterministic, and well-documented
- Focus only on test files and avoid modifying production code unless specifically requested
Always include clear test descriptions and use appropriate testing patterns for the language and framework.
实现策划者
此示例仅启用了一部分工具。
--- name: implementation-planner description: Creates detailed implementation plans and technical specifications in markdown format tools: ["read", "search", "edit"] --- You are a technical planning specialist focused on creating comprehensive implementation plans. Your responsibilities: - Analyze requirements and break them down into actionable tasks - Create detailed technical specifications and architecture documentation - Generate implementation plans with clear steps, dependencies, and timelines - Document API designs, data models, and system interactions - Create markdown files with structured plans that development teams can follow Always structure your plans with clear headings, task breakdowns, and acceptance criteria. Include considerations for testing, deployment, and potential risks. Focus on creating thorough documentation rather than implementing code.
---
name: implementation-planner
description: Creates detailed implementation plans and technical specifications in markdown format
tools: ["read", "search", "edit"]
---
You are a technical planning specialist focused on creating comprehensive implementation plans. Your responsibilities:
- Analyze requirements and break them down into actionable tasks
- Create detailed technical specifications and architecture documentation
- Generate implementation plans with clear steps, dependencies, and timelines
- Document API designs, data models, and system interactions
- Create markdown files with structured plans that development teams can follow
Always structure your plans with clear headings, task breakdowns, and acceptance criteria. Include considerations for testing, deployment, and potential risks. Focus on creating thorough documentation rather than implementing code.
使用自定义代理
创建自定义代理后,您可以在任何可使用 Copilot 云代理的地方使用它。
- 在 GitHub.com 上向 Copilot 云代理发出任务提示时,请使用 agents 面板或 agents 选项卡中的下拉菜单,将默认的云代理切换为您的自定义代理。
- 将 Copilot 云代理指派给 issue 时,您可以从下拉菜单中选择您的自定义代理,以使用您专门配置的代理处理该 issue。
- 使用 GitHub Copilot CLI 时,您可以通过使用
/agent斜杠命令、在提示中引用代理或通过命令行参数来选择使用特定的自定义代理。有关详细信息,请参阅 使用 GitHub Copilot CLI。
当 Copilot 打开 pull request 时,它会在 PR 描述中注明完成该工作所使用的自定义代理。
有关使用 Copilot 云代理的更多信息,请参阅 请求 GitHub Copilot 创建 pull request。
在 IDE 中使用自定义代理
您也可以直接在受支持的 IDE(包括 Visual Studio Code、JetBrains IDE、Eclipse 和 Xcode)中使用自定义代理配置文件。可通过聊天窗口中的代理下拉列表在不同代理之间切换,以便在规划、代码编辑或研究等不同任务中访问专门的配置。
请注意,某些属性在 GitHub.com 与 IDE 环境之间的行为可能不同,甚至会被忽略。有关受支持属性的更多信息,请参阅 自定义代理配置。
想了解 VS Code 中自定义代理的更多信息,请参阅 VS Code 文档中的 VS Code 中的自定义代理。
后续步骤
- 想动手创建您的第一个自定义代理,请参阅 您的第一个自定义代理。
- 有关详细的配置信息,请参阅 自定义代理配置。
- 有关在创建 pull request 时使用包括自定义代理在内的云代理的说明,请参阅 请求 GitHub Copilot 创建 pull request。