{"meta":{"title":"调用自定义代理","intro":"使用Copilot CLI中的自定义代理、技能和MCP服务器来增强其功能。","product":"GitHub Copilot","breadcrumbs":[{"href":"/zh/enterprise-cloud@latest/copilot","title":"GitHub Copilot"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos","title":"操作方法"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos/copilot-cli","title":"Copilot CLI"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos/copilot-cli/use-copilot-cli","title":"使用 Copilot CLI"},{"href":"/zh/enterprise-cloud@latest/copilot/how-tos/copilot-cli/use-copilot-cli/invoke-custom-agents","title":"调用自定义代理"}],"documentType":"article"},"body":"# 调用自定义代理\n\n使用Copilot CLI中的自定义代理、技能和MCP服务器来增强其功能。\n\n## 使用 custom agents\n\ncustom agent 是 Copilot 的专用版本。\nCustom agents 帮助 Copilot 处理独特的工作流、特定的编码约定和专家用例。\n\nCopilot CLI 包括一组用于常见任务的默认 custom agents：\n\n<table>\n  <thead>\n    <tr>\n      <th style=\"width:20%\">Agent</th>\n      <th>Description</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <td>探索</td>\n      <td>执行快速代码库分析，让你无需添加到主上下文即可提出有关代码的问题。</td>\n    </tr>\n    <tr>\n      <td>任务</td>\n      <td>执行测试和构建等命令，在成功时提供简要总结，在失败时提供完整输出。</td>\n    </tr>\n    <tr>\n      <td>常规用途</td>\n      <td>处理复杂的多步骤任务，这些任务需要完整的工具集和高质量的推理，在单独的上下文中运行，以使主对话保持清晰焦点。</td>\n    </tr>\n    <tr>\n      <td>代码评审</td>\n      <td>审查更改时，专注于揭示真正的问题，尽量减少干扰。</td>\n    </tr>\n  </tbody>\n</table>\n\nCLI 使用的 AI 模型可以选择将任务委托给一个使用具有特定专业知识的 custom agent 运行的附属子代理进程，前提是它认为这样做可以更有效地完成工作。 此模型同样可以选择直接在主智能体中处理工作。\n\n可以使用 Markdown 文件（称为custom agents）定义自己的agent profiles内容，这些文件指定代理应具备哪些专业知识、可以使用哪些工具，以及响应方式的任何特定说明。\n\n可以在用户、存储库、组织或企业级定义 custom agents ：\n\n| 类型                               | 位置                                                                                                                                                                                                           | Scope      |\n| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------- |\n| 用户级别 custom agent                | 本地 `~/.copilot/agents` 目录                                                                                                                                                                                    | 所有项目       |\n| 存储库级别 custom agent               |                                                                                                                                                                                                              |            |\n| `.github/agents` 本地存储库和远程存储库中的目录 | 当前项目                                                                                                                                                                                                         |            |\n| 组织级别 custom agent                | 组织的 `/agents` 或 `.github` 存储库中的 `.github-private` 目录                                                                                                                                                         | 组织内的所有项目   |\n| 企业级 custom agent                 | 企业设置中指定的组织的 `/agents` 存储库中的 `.github-private` 目录。 有关详细信息，请参阅“[准备在企业中使用自定义代理](/zh/enterprise-cloud@latest/copilot/how-tos/administer-copilot/manage-for-enterprise/manage-agents/prepare-for-custom-agents)”。 | 企业帐户下的所有项目 |\n\n如果命名冲突（其中代理共享同一文件名），用户级代理会替代存储库级代理，存储库级代理会替代组织级代理，而组织级代理将替代企业级代理。\n\nCustom agents 可通过三种方式使用：\n\n* 使用 CLI 交互式接口中的斜杠命令从可用 custom agents列表中进行选择：\n\n  ```shell\n  /agent\n  ```\n\n* 在提示中直接调用custom agent：\n\n  ```shell\n  Use the refactoring agent to refactor this code block\n  ```\n\nCopilot 将自动推断要使用的代理。\n\n* 使用命令行选项指定要使用的 custom agent。 例如：\n\n  ```shell\n  copilot --agent=refactor-agent --prompt \"Refactor this code block\"\n  ```\n\n有关详细信息，请参阅“[为Copilot cloud agent创建自定义代理](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/create-custom-agents)”。\n\n## 使用技能\n\n可以创建技能，以增强 Copilot 使用说明、脚本和资源来执行专用任务的能力。\n\n有关详细信息，请参阅“[为 GitHub Copilot CLI 添加代理技能](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-cli/customize-copilot/add-skills)”。\n\n## 添加 MCP 服务器\n\nCopilot CLI附带已配置的GitHubMCP 服务器。 此 MCP 服务器允许你与资源 GitHub.com进行交互，例如，允许你合并 CLI 中的拉取请求。\n\n若要扩展可用 Copilot CLI功能，可以添加更多 MCP 服务器：\n\n1. 使用以下斜杠命令：\n\n   ```shell\n   /mcp add\n   ```\n\n2. 填写你想要添加的 MCP 服务器的详细信息，使用 <kbd>Tab</kbd> 键在各个字段之间切换。\n\n3. 按<kbd> Ctrl</kbd>+<kbd>S</kbd> 以保存详细信息。\n\n你已配置的 MCP 服务器详细信息存储在 `mcp-config.json` 文件中，该文件默认位于 `~/.copilot` 目录下。 可通过设置 `COPILOT_HOME` 环境变量来更改此位置。 有关服务器定义的 JSON 结构的信息，请参阅“[为存储库配置 MCP 服务器](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-on-github/customize-copilot/configure-mcp-servers#writing-a-json-configuration-for-mcp-servers)”。\n\n有关添加和管理 MCP 服务器 Copilot CLI的详细信息，请参阅 [为 GitHub Copilot CLI 添加 MCP 服务器](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-cli/customize-copilot/add-mcp-servers)。\n\n## 后续步骤\n\n若要了解如何在任务执行期间指导和优化代理行为，以跟踪工作，请参阅 [引导 GitHub Copilot CLI 中的智能体](/zh/enterprise-cloud@latest/copilot/how-tos/copilot-cli/use-copilot-cli/steer-agents)。"}