Skip to main content

为你的项目自定义Copilot

在GitHub上设置自定义设置、创建专用代理,并整理项目上下文。

本快速入门将指导你完成存储库的自定义 GitHub Copilot 。 最后, Copilot 将知道项目的约定,具有用于常见任务的专用代理,并具有特选的项目上下文。

          **场景:** 你在一个团队的 Web 应用程序存储库上工作,该存储库已建立了测试套件、编码约定,并有活跃的问题管理。 你希望 Copilot 从第一天起有效地使用代码库。

先决条件

步骤 1:传授 Copilot 项目的惯例

存储库自定义说明为项目提供 Copilot 持久上下文-其结构、编码标准以及如何生成和测试代码。 Copilot存储库中的每个交互都会自动应用这些指令。

请求 Copilot云代理 生成 copilot-instructions.md 文件:

  1. 转到 github.com/copilot/agents

  2. 从提示字段中的下拉菜单中选择存储库。

  3. 输入以下提示:

    Text
    Onboard this repository to Copilot cloud agent by adding a
    .github/copilot-instructions.md file. Include information about project
    structure, coding conventions, the test framework, and how to build and
    run the project.
    
  4. 查看生成的文件并合并拉取请求。

           Copilot 现在可以全面了解项目在聊天、代码评审和代理会话中的约定。 请参阅“[AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/add-custom-instructions/add-repository-instructions)”。
    

步骤 2:创建专用代理

          自定义智能体 允许为定期任务创建重点助手。 在此示例中,创建诊断和修复 bug 的代理。
  1. 转到 github.com/copilot/agents 并选择存储库。

  2. 在提示字段中,单击 。 然后单击“ 创建自定义代理”。

  3. 将文件重命名为 bug-fixer.agent.md

  4. 将模板内容替换为:

    YAML
    ---
    name: Bug Fixer
    description: Diagnoses and fixes bugs reported in GitHub issues.
    tools:
      - read
      - edit
      - terminal
      - search
    ---
    
    You are a bug-fixing specialist. When given a bug report or issue:
    
    1. Reproduce the bug by writing a failing test.
    2. Identify the root cause.
    3. Fix the code.
    4. Verify the fix passes the test and doesn't break existing tests.
    
    Always follow the project's testing conventions and coding standards.
    
  5. 提交文件并将其合并到默认分支中。

您的错误修复代理现在显示在“代理”选项卡内的“代理”下拉列表中。在粘贴问题 URL 之前,先选择它以开始专注调试会话。 请参阅“为Copilot云代理创建自定义代理”。

步骤 3:使用空格组织项目上下文

          Copilot空间 允许你为项目的特定区域提供定制的上下文支持 Copilot 。 答案以相关文件、问题和文档为基础。
  1. 转到 github.com/copilot/spaces 并单击“ 创建空间”。

  2. 命名空间(例如“API 体系结构”),然后选择所有者。

  3. 单击“ 添加源”,然后添加与项目相关的上下文:


           <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-file-code" aria-label="file-code" role="img"><path d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2.5a.75.75 0 0 1-1.5 0Zm1.72 4.97a.75.75 0 0 1 1.06 0l2 2a.75.75 0 0 1 0 1.06l-2 2a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l1.47-1.47-1.47-1.47a.75.75 0 0 1 0-1.06ZM3.28 7.78 1.81 9.25l1.47 1.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-2-2a.75.75 0 0 1 0-1.06l2-2a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042Zm8.22-6.218V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path></svg> 添加文件和存储库** - 添加体系结构文档、API 架构或关键配置文件。
    

           <svg version="1.1" width="16" height="16" viewBox="0 0 16 16" class="octicon octicon-link" aria-label="link" role="img"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg> 链接文件、拉取请求和问题** - 粘贴活动问题或设计讨论的 URL。
    
  4. 在空间的聊天中,问一个问题,比如:“我们的 API 使用什么模式进行错误处理?”

           Copilot 仅使用你整理的上下文的答案。 请参阅“[AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/copilot-spaces/create-copilot-spaces)”。
    

后续步骤


          [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/add-custom-instructions/add-personal-instructions)** - 设置适用于所有存储库的个人首选项。

          [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/add-skills)** - 向代理添加新功能。

          [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/customize-cloud-agent/extend-cloud-agent-with-mcp)** — 将代理连接到外部工具和服务。

          [AUTOTITLE](/copilot/how-tos/copilot-on-github/customize-copilot/copilot-spaces/collaborate-with-others)** - 与队友共享空间。