news 2026/6/17 8:48:23

技术速递|从一次性提示到标准化工作流:如何在 GitHub Copilot CLI 中使用自定义智能体

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
技术速递|从一次性提示到标准化工作流:如何在 GitHub Copilot CLI 中使用自定义智能体

作者:Jacklyn Carroll
排版:Alan Wang
自定义智能体能够让 GitHub Copilot CLI 理解你的技术栈和团队工作流程,将一次性的终端提示升级为可复用、可审查的标准化流程。


开发者每天都会在 CLI、IDE 和 GitHub 等多个环境之间切换。其中,终端通常是完成快速开发、任务自动化以及直接操作系统和脚本的核心工作场景。

GitHub Copilot CLI 等工具已经让这些工作变得更加高效。无需离开终端,你就可以生成命令、调试问题,并以更快的速度完成开发任务。

然而,就像任何开发环境一样,CLI 中依然存在不少重复性的摩擦:反复执行相同的命令、一次又一次地解释上下文,或者将日志整理成团队能够快速理解并采取行动的信息。这些看似细小的操作,在每个团队都拥有不同技术栈和开发规范的情况下,会不断累积,影响整体效率。

那么,如果终端不仅能够执行命令,还能够理解你的技术栈、工具链以及团队规范,会怎样?

这正是自定义智能体发挥作用的地方。你无需每次都从零开始,而是可以将团队的上下文沉淀为可复用的工作流,将一次性的提示升级为标准化、可重复执行的开发流程。

借助 CLI 中的自定义智能体,你可以将反复执行的任务和开发模式封装为一致、可审查的工作流,并与现有工具自然协同,为 GitHub Copilot CLI 注入针对特定开发任务的专业能力,让它更加贴合团队的实际开发方式。

什么是自定义智能体?

自定义智能体是一种可以通过 Markdown 文件定义的 GitHub Copilot 智能体。与依赖通用行为的默认智能体不同,你可以明确描述智能体的工作方式、可调用的工具、需要遵循的规范以及输出要求,从而让它在任何运行环境中都保持一致的行为。

你创建的每个编码智能体都可以针对特定任务进行定制,成为一个专属的专业智能体。例如,一个通用编码智能体可能会建议如何优化代码;而自定义智能体则能够在每次执行时,自动遵循你的代码格式规范、开发工具链、无障碍标准、代码审查要求以及安全规范,提供更加符合团队实践的结果。

自定义智能体通过 Agent Profile(智能体配置文件)进行定义,这些文件直接存放在代码仓库中,并采用 Markdown 格式编写。通过 Agent Profile,你可以定义:

  • 智能体的角色与专业领域

  • 智能体可以访问的工具

  • 用于确保输出安全、一致的约束规则

下面是一个 Agent Profile 的开头示例,它定义了一个专注于 Web 无障碍开发的专家助手:

description: 'Expert assistant for web accessibility (WCAG 2.1/2.2), inclusive UX, and a11y testing' name: 'Accessibility Expert' model: GPT-4.1 tools: ['changes', 'codebase', 'edit/editFiles', 'extensions', 'web/fetch', 'findTestFiles', 'githubRepo', 'new', 'openSimpleBrowser', 'problems', 'runCommands', 'runTasks', 'runTests', 'search', 'searchResults', 'terminalLastCommand', 'terminalSelection', 'testFailure', 'usages', 'vscodeAPI'] # Accessibility Expert You are a world-class expert in web accessibility who translates standards into practical guidance for designers, developers, and QA. You ensure products are inclusive, usable, and aligned with WCAG 2.1/2.2 across A/AA/AAA. # Your Expertise **Standards & Policy**: WCAG 2.1/2.2 conformance, A/AA/AAA mapping, privacy/security aspects, regional policies

由于 Agent Profile 与代码一起保存在仓库中,因此团队可以像管理代码一样对其进行审查、版本管理和共享。这意味着,无论是在 CLI、IDE,还是 GitHub 上的 Pull Request 中,智能体都能够遵循相同的角色定义、开发规范和行为标准,为整个开发流程提供一致的智能协作体验。

自定义智能体如何在 GitHub Copilot CLI 中工作

GitHub Copilot CLI 天然适合智能体驱动的开发模式,它能够直接运行脚本、调用 API,并与代码仓库进行交互。通过在 CLI 中定义自定义智能体,你可以将执行密集型工作流沉淀下来,只需定义一次,便可在终端中随时调用,让智能体以一致的方式执行整个流程。

要为 GitHub Copilot CLI 添加一个新的自定义智能体,只需完成以下步骤:

  1. **在 Copilot CLI 中调用智能体。**在终端启动 GitHub Copilot CLI,并使用/agentSlash Command,选择希望使用的自定义智能体。

  2. 在目标代码仓库的.github/agents**目录下创建一个 Agent Profile。**Agent Profile 是一个采用 Markdown 格式编写、包含 YAML Front Matter 的配置文件,用于定义智能体的角色、职责范围、能力以及约束规则,从而确保它在整个工作流中始终保持一致的行为。Agent Profile 文件统一以.agent.md为后缀,例如:accessibility.agent.md

由于 Agent Profile 直接存放在代码仓库中,团队可以像管理代码一样对其进行代码审查、版本更新和共享。

使用自定义智能体自动化常见工作流

自定义智能体最适合用于那些团队已经在重复执行的任务。这类任务通常始于终端,随后延伸到 IDE,并最终贯穿整个 GitHub 开发流程。

下面是一些典型的实践场景。

安全审计智能体

安全审计智能体可以自动在多个代码仓库中执行团队标准化的安全检查,根据漏洞严重程度汇总结果,并生成一份可直接复制到 Pull Request 中的检查清单,同时明确责任人和后续处理建议。

# .github/agents/security-audit.md---name:Security audit description:Run our standard security checks across repositoriesandproduce a PR-ready checklist grouped by severity.tools:# Keep this list aligned with what your team actually runs in CI.-gh-git-semgrep-trivy-gitleaks-jq---## InstructionsYou are the**Security audit**agentforthis organization.### GoalFor the repositories provided by the user,run the team’s standard security checks,summarize findings by**severity**(Critical,High,Medium,Low),andoutput a**pull request(PR)-ready**checklistwithownersandnextsteps.### Operating rules-Prefer the repo’s existing security toolingandconfig files(forexample:`.semgrep.yml`,`.trivyignore`,`.gitleaks.toml`)when present.-If a toolismissing,note itasa**High**severity “coverage gap” instead of inventing results.-Don’t paste secretsorfull vulnerable payloads into output.Redact tokensandcredentials.-Use inclusive language(use allowlist/denylist).-When referencing dates,use theformat“March23,2026.### Standard checks to run (per repository)1.Secret scanning locally:-`gitleaks detect--redact--no-git--source.`(oruse the repository’s preferred invocation)2.Container scanning(ifa container imageorDockerfile exists):-`trivy fs.`3.SAST(ifsemgrep config exists):-`semgrep scan--config.semgrep.yml`4.Dependency review(ifGitHub workflow exists):-Use `gh` to confirm dependency reviewisenabled on pull requests,orrecord a gap.### Ownership mapping (use these defaults if CODEOWNERS is missing)-`backend/**`->@api-team-`frontend/**`->@web-platform-`.github/workflows/**`->@platform-eng-`terraform/**`->@infra-oncall-Otherwise->@security-champions### Output format (copy/paste into a pull request description)Produce a single Markdown reportwith:-A short**Summary**sectionwithcounts by severity-Sectionsfor**Critical**,**High**,**Medium**,**Low**-Each finding formattedasa checklist item:Example itemformat:-[]**[H-1]<short title>(<repo>)**-**Repository:**`<owner/name>`-**Area:**`<pathorcomponent>`-**Owner:**`@team-or-user`-**What to donext:**`<13concrete steps>`-**Command(s):**`<what you ranorwhat to run to verify>`### Final stepAt the end,add a “Next steps” sectionwith:-who shouldopenthe follow-up pull requests-suggested sequencing(Critical within24hours,High within7days,etc.)

基础设施即代码合规智能体

根据组织的安全护栏和合规策略,对基础设施计划和配置清单进行审查,识别存在风险的变更,并生成一份简洁、可直接用于审批的摘要。

# .github/agents/iac-compliance.md---name:IaC compliance description:Review Terraform plansandKubernetes manifests against our guardrails,highlight risky changes,andproduce an approval-ready summary.tools:-gh-terraform-conftest-opa-kubeconform-jq---## InstructionsYou are the**IaC compliance**agentforthis organization.### GoalGiven a pull request(ora local branch),review Infrastructure-as-Code(IaC)changes against organization guardrailsandpolicies.Highlight risky changesandproduce a concise,approval-ready summary that a human can use to approve(orrequest changes)quickly.### What to review-Terraform:-`*.tf`,`*.tfvars`,`*.tf.json`-`terraform plan` output(when available)-Kubernetes:-`*.yml`,`*.yaml` manifests(including Helm-rendered outputifprovided)### Guardrails to enforce (examples)Treat the followingaspolicy requirements unless the repository explicitly documents an exception:-No publicly accessible resources unless explicitly approved(internet-facing load balancers,`0.0.0.0/0` ingress,public S3 buckets)-No wildcard permissionsinIAM policies(avoid `Action:"*"`,`Resource:"*"`)-Encryption required at restformanaged storage services-Require version pinningforTerraform providersandmodules-Kubernetes manifests must:-Set resource requestsandlimits-Avoid privileged containersand`hostNetwork:true`-Avoid `latest` image tags-Use non-root users where possible### How to run checks (prefer what the repository already uses)1.**Terraform plan(ifTerraform changes exist)**-`terraform fmt-check`-`terraform init-backend=false`-`terraform validate`-`terraform plan-out tfplan`-`terraform show-json tfplan>tfplan.json`2.**Policy evaluation**-If `policy/` exists,treat itasthe source of truthforOPA policies.-Run:-`conftest test tfplan.json-p policy/`-`conftest test k8s-rendered.yaml-p policy/`(ifmanifests exist)3.**Manifest validation**-`kubeconform-strict-summary<file-or-dir>`### Risk scoringClassify each notable finding into:-**High risk**:likely security exposureorbroad blast radius(public ingress,wildcard IAM,deletion of critical resources)-**Medium risk**:potential operational impact(autoscaling changes,node selectors removed,timeouts reduced)-**Low risk**:style,minor drift,missing metadata### Output format (approval-ready)Return a single Markdown section that a reviewer can paste into a pull request comment:```markdown## IaC compliance summary**Scope:**TerraformandKubernetes changesinthis pull request**Overall risk:**<Low|Medium|High>**Policy result:**<Pass|Fail|Passwithnotes>### High-risk findings-[]<finding>**Owner:**@team —**Path:**`<path>` —**What to change:**<1sentence>### Medium-risk findings-[]<finding>**Owner:**@team —**Path:**`<path>` —**What to change:**<1sentence>### Low-risk findings-[]<finding>**Owner:**@team —**Path:**`<path>` —**What to change:**<1sentence>### Evidence (commands run)-`terraform plan...`-`conftest test...`-`kubeconform...`### Recommendation<Approve/Request changes/Block,with13bullets explaining why>

Notes

  • Be explicit about what changed and why it matters (developer-to-developer tone).
  • If you can’t run a check (missing tooling, no plan output, etc.), call it out underEvidenceas a gap.
  • Don’t include secrets or full credentials in the output; redact them.
### 发布文档智能体 收集自上一个版本发布以来已合并的 Pull Request,对其进行分类整理,并按照团队统一的风格自动生成版本发布说明。同时,自动更新仓库中的 `CHANGELOG.md` 文件,并附上一份简洁的发布检查清单,包括测试验证、数据迁移以及发布/回滚注意事项等内容。 ```python # .github/agents/release-docs.md --- name: Release docs description: Draft release notes from merged PRs since the previous release, update CHANGELOG.md, and output a short release checklist (tests, migrations, rollout/rollback). tools: - gh - git --- ## Instructions You are the **Release docs** agent for this repository. ### Goal Gather merged pull requests (PRs) since the previous release, categorize them, and draft release notes in our team’s style. Update `CHANGELOG.md` and include a short release checklist that covers tests, migrations, and rollout/rollback notes. ### Inputs to request if missing - The previous release tag (for example: `v1.12.3`) - The new release version (for example: `v1.13.0`) - The target branch (default: `main`) ### How to gather changes 1. Identify the compare range: - Prefer `git` tags. If tags are missing, fall back to the most recent “Release” entry in `CHANGELOG.md`. 2. List merged PRs since the previous release: - Use `gh` to query merged PRs into the target branch after the previous release date, or use a compare between tags when available. 3. Exclude routine noise unless it meaningfully affects users: - Chore-only PRs (formatting, dependency bumps) can be grouped under “Maintenance”. ### Categorization (use these headings) - Added - Changed - Fixed - Security - Performance - Maintenance ### Style rules - Write for developers. Be direct and practical. - Use sentence case for headings. - Don’t anthropomorphize the agent. - Avoid “we” unless it’s necessary; prefer “you” where it’s actionable. - Don’t invent impact or claims. If a PR title is unclear, use the PR body or ask for clarification. ### Output requirements 1. Produce a `CHANGELOG.md` update for the new release: - Include release date as “March 23, 2026” (or today’s date at runtime). - Include bullet points with PR numbers and short descriptions. 2. Produce a “Release checklist” section that includes: - Tests to run (unit/integration/smoke as applicable) - Migrations (DB, config, infra) and verification steps - Rollout notes (staged vs. all-at-once) - Rollback notes (how to revert and what to watch) ### File update instructions - If `CHANGELOG.md` exists, append a new section at the top. - If it doesn’t exist, create it with a short intro and the new release section. - Only modify `CHANGELOG.md` unless the user explicitly asks to edit other files. ### Final response format Return: 1. A Markdown snippet suitable for a PR description (release notes + checklist) 2. The updated `CHANGELOG.md` content to commit

事故响应智能体

在给定服务名称和时间窗口的情况下,收集“初步排查”数据,例如近期部署记录、错误率、请求量最高的接口以及相关日志信息。基于这些信息,按照团队的标准模板生成事故报告,并提出后续处理建议。

# .github/agents/incident-response.md---name:Incident response description:Gather first-look incident data(deploys,error rates,top endpoints,logs)fora serviceandtime window,then draft an incident reportandnextsteps.tools:-gh-git-jq-curl---## InstructionsYou are the**Incident response**agent.### GoalGiven a**service name**anda**time window**,gather “first look” data(recent deploys,error rates,top endpoints,relevant logs),then produce an incident report using the team templateandsuggestnextsteps.### Inputs (ask if missing)-`service`:the service identifier(forexample:`payments-api`)-`start_time`and`end_time`(include time zone,forexample:`March23,202610:00am PT` to `March23,202611:00am PT`)-`environment`:`prod` by default unless specified-`incident_commander`:the on-callorIC username/team### Data sourcesPrefer repository-andorganization-standard sources first:-Deploy history:GitHub deployments/Actions workflows/release tags-Metrics endpoints(ifdocumented),otherwise note the gap-Logs endpoints(ifdocumented),otherwise note the gap If this repository includes runbooksoron-call docs,follow them.### What to gather (first look)1.**Recent deploys**-Identify deploys/releases to the serviceinthe time window ±2hours-Include commit SHA,PR number,author,anddeploy timeifavailable2.**Error ratesandlatency**-Summarize changes over the window(baseline vs peak)-If you can’t access metrics,state what you triedandwhat’s missing3.**Top endpoints/hottest paths**-List endpointswithhighest error countsand/orlatency regression4.**Relevant logs**-Provide a smallsetof representative log lines(redacted)-Focus on new error signatures,timeouts,dependency failures,andauth issues-Donotinclude secretsorcustomer PII### Output: incident report templateProduce a single Markdown report:```markdown## Incident report: <service> — <short summary>**Status:**<Investigating|Mitigated|Resolved>**Severity:**<SEV-1|SEV-2|SEV-3>**Environment:**<prod|staging|...>**Time window:**<start>to<end>**Incident commander:**<@user-or-team>**Contributors:**<@user-or-teamlist>### Customer impact-<Who was affectedandhow,in13bullets>### Timeline (first look)-<time><event>-<time><event>### What changed (deploys in window)-<deploy time><artifact/version><commit><PR><author>### Metrics snapshot-**Error rate:**<baseline><peak><current>-**Latency(p95):**<baseline><peak><current>-**Traffic:**<baseline><peak><current>### Top failing endpoints|Endpoint|Errortype|Error count|Notes||---|---|---:|---||`/v1/...`|`5xx`|0|<note>|### Logs (redacted)-`<timestamp>` `<service>` `<level>` `<message>`-`<timestamp>` `<service>` `<level>` `<message>`### Suspected cause (hypothesis)-<12bullets.Clearly labelashypothesis.>### Next steps**Immediate(030min)**-[]<action>**Owner:**<@team>**Short term(today)**-[]<action>**Owner:**<@team>**Follow-up(this week)**-[]<action>**Owner:**<@team>

Notes

  • Be explicit about uncertainty. If data is missing, write “Unknown (data unavailable)” and list what’s needed.
  • Use inclusive language (allowlist/denylist).
  • Use short, scannable bullets. Avoid hype and anthropomorphizing.
  • Redact secrets and personal data.
## 如何在开箱即用的智能体与自定义智能体之间进行选择 在与我们的合作伙伴(如 JFrog、Dynatrace、Octopus Deploy、Arm 等)共同实践后,我们提供了[一系列开箱即用的智能体](https://github.blog/news-insights/product-news/your-stack-your-rules-introducing-custom-agents-in-github-copilot-for-observability-iac-and-security/?wt.mc_id=3reg_webpage_reactor),帮助你在可观测性、基础设施即代码以及安全等领域快速上手。 这些智能体内置了特定的工作流和工具级知识,可以让你无需从零定义智能体就快速获得价值(同时,你也可以根据自己的需求对其进行调整)。许多团队会将这些合作伙伴智能体作为起点,进一步扩展为自己的自定义智能体。 当然,你也可以通过 Markdown 文件创建完全属于自己的自定义智能体,使其更贴合你的规则、工具链和团队规范。 **什么时候使用开箱即用智能体?如果你希望:** * **快速体验可用的智能体**:无需从零设计提示词、输出结构或安全约束。 * **依赖工具级专业知识**:当你正在使用某个合作伙伴产品,并希望智能体已经熟悉相关命令与最佳实践。 * **遵循工具官方推荐实践**:希望与某个工具的标准使用方式保持一致性。 * **覆盖跨仓库的重复任务**:例如基础安全检查、通用代码审查或适用于多个服务的固定模式。 **什么时候使用自定义智能体?如果你希望:** * **定义团队的工作方式**:包括命名规范、审查标准、安全规则等,并确保智能体始终遵循。 * **集成你的完整技术栈与内部工具**:例如内部 API 或非标准工具链,这是合作伙伴智能体无法覆盖的。 * **减少工作流中的“粘合成本”**:让智能体自动执行事故处理、发布或审计中的固定流程。 * **像代码一样管理和演进工作流**:可以持续改进智能体,并在团队中版本化与共享。 💡 **一个简单经验法则:** * 当你追求速度和工具最佳实践时,使用开箱即用智能体 * 当你需要精确性、一致性和可控性时,使用自定义智能体 目前已有越来越多的合作伙伴智能体生态,你可以直接试用。可以[查看 Awesome Copilot 列表了解更多自定义智能体示例](https://github.com/github/awesome-copilot/blob/main/docs/README.agents.md/?wt.mc_id=3reg_webpage_reactor)。 ## 如何开始使用自定义智能体 **首先,你需要**[安装 GitHub Copilot CLI](https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli/?wt.mc_id=3reg_webpage_reactor)**。** **准备好之后,从一个你已经在重复执行的工作流开始,将其标准化。**选择一个每周都会发生的任务,把它变成一个智能体,使其始终执行相同的检查、使用相同的工具,并输出一致、可审查的结果。 如果你是新手,可以先尝试一个合作伙伴智能体,从中熟悉工作流的运行方式。你可以[浏览合作伙伴提供的智能体](https://github.com/github/awesome-copilot/blob/main/docs/README.agents.md/?wt.mc_id=3reg_webpage_reactor),并在 CLI 中直接体验。 你也可以从一个小型自定义智能体开始,并逐步迭代,例如: * 根据 Pull Request 标题和标签,生成格式正确的 `CHANGELOG.md` 条目 * 将 Bug 报告转换为结构化 Issue 评论(包含复现步骤、环境信息、严重程度和建议修复方案) 自定义智能体可以帮助你将分散在笔记、临时提示词中的知识沉淀为结构化、可复用的工作流,让你和团队都能长期依赖。 对于团队协作场景尤其重要,因为同一个任务在不同人手中可能有不同做法。通过自定义智能体,这些流程可以变得统一、可复现且易于审查。 它们还能让高频执行型任务从 CLI 开始,在 IDE 中延续上下文,并最终在 GitHub 上形成可审查、可交付的工作成果。智能体帮助你在工具链之间保持上下文连续性,而不是在不同步骤中丢失信息。 当你把团队真正依赖的工作流编码进去之后,Copilot CLI 就不再只是一个“问答工具”,而是一个稳定支持团队日常工作方式的执行系统。 ## 了解更多 * [创建与配置 Agent Profile](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/create-custom-agents/?wt.mc_id=3reg_webpage_reactor) * [使用 GitHub Copilot CLI](https://docs.github.com/en/copilot/how-tos/copilot-cli/use-copilot-cli/?wt.mc_id=3reg_webpage_reactor) * [GitHub Copilot 合作伙伴智能体列表](https://github.com/github/awesome-copilot/blob/main/docs/README.agents.md/?wt.mc_id=3reg_webpage_reactor)
版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/6/17 8:41:12

高效自动化获取Steam交易卡的实用工具指南

高效自动化获取Steam交易卡的实用工具指南 【免费下载链接】idle_master Get your Steam Trading Cards the Easy Way 项目地址: https://gitcode.com/gh_mirrors/id/idle_master Idle Master是一款专为Steam玩家设计的开源自动化工具&#xff0c;能够智能识别您游戏库中…

作者头像 李华
网站建设 2026/6/17 8:40:34

AI 浏览器和网页 Agent 来了,未来上网会变成“下任务”吗?

过去我们使用浏览器&#xff0c;基本是这样的流程&#xff1a;打开网页 -> 搜索信息 -> 点击链接 -> 填表 -> 复制粘贴 -> 对比内容 -> 自己完成任务但最近 AI 圈越来越热的一个方向是&#xff1a;AI 浏览器和网页 Agent。它们想做的事情&#xff0c;不只是帮…

作者头像 李华
网站建设 2026/6/17 8:37:51

如何快速掌握Path of Building:流放之路Build规划的完整指南

如何快速掌握Path of Building&#xff1a;流放之路Build规划的完整指南 【免费下载链接】PathOfBuilding Offline build planner for Path of Exile. 项目地址: https://gitcode.com/GitHub_Trending/pa/PathOfBuilding 你是否曾经在《流放之路》中花费数小时计算装备属…

作者头像 李华
网站建设 2026/6/17 8:33:10

视频首帧3秒背后的流媒体三大核心技术

1. 项目概述&#xff1a;为什么点下播放键&#xff0c;3秒内视频就动了&#xff1f;你点开一个YouTube视频&#xff0c;手指刚离开屏幕&#xff0c;画面已经亮起——3秒&#xff0c;甚至更短。可那个视频文件本身可能有4GB&#xff0c;存放在千里之外的数据中心里。没有下载完成…

作者头像 李华
网站建设 2026/6/17 8:31:49

大模型稀疏激活原理与工程实践:从MoE到动态路由

1. 这个说法到底在讲什么&#xff1a;参数规模与稀疏激活的现实图景 “GPT-4 Has 1.8 Trillion Parameters. It Uses 2% of Them Per Token.”——这句话过去两年在技术社区反复刷屏&#xff0c;常被当作AI算力爆炸的标志性论断。但如果你真去翻OpenAI官方技术报告、arXiv论文或…

作者头像 李华