Levix

Levix's zone

x
telegram

全面了解 GitHub Copilot 的强大模式

image

Last month, we released agent mode as a step toward building GitHub Copilot into a system that not only works with you, but works for you. When you give it a natural-language prompt, Copilot’s agent mode works to execute it on your behalf, automating processes and workflows that would otherwise take a lot of time and giving you space to focus on higher-level problem solving.​ 
上个月,我们发布了代理模式,这是将 GitHub Copilot 打造为不仅协同工作、更能主动代劳的系统的重要一步。当您输入自然语言指令时,Copilot 的代理模式会代表您执行操作,自动化原本耗时的流程和工作流,让您能专注于更高层次的问题解决。

For those who are newer to coding, agent mode can be a useful synchronous tool when it comes to developing an app (whereas our new preview of coding agent in Copilot offers asynchronous task completion capabilities). But it’s equally, if not more so, an incredibly useful tool for more seasoned developers looking to work faster. With agent mode, you can quickly move from prompting Copilot with a higher-level requirement to testing out a prototype. Plus, we’re still seeing new use cases unfold among developers of all levels. 
对于编程新手而言,代理模式是开发应用程序时实用的同步工具(而我们在 Copilot 中最新推出的编码代理预览版则提供异步任务完成能力)。但同样甚至更重要的是,它对于追求效率的资深开发者来说也是极其强大的工具。通过代理模式,您可以从提出高层次需求快速推进到测试原型阶段。此外,我们持续观察到不同水平开发者都在发掘新的应用场景。

Let’s take a closer look at what agent mode is, how it works, and how you can use it. 
让我们深入了解代理模式的定义、工作原理及使用方法。

But first, what is GitHub Copilot agent mode? 
但首先,什么是 GitHub Copilot 代理模式?#

GitHub Copilot agent mode is an autonomous and agentic real-time, synchronous collaborator that performs multi-step coding tasks based on natural-language prompts. More simply, it’s a problem solver that understands your intent, builds a solution, and iterates until it gets it right. 
GitHub Copilot 代理模式是一个自主的、具备代理能力的实时同步协作工具,能够基于自然语言提示执行多步骤编码任务。简而言之,它是一个能理解你的意图、构建解决方案并持续迭代直至正确的智能问题解决者。

Agent mode can: 智能代理模式能够:

  • Analyze your codebase to grasp the full context.
    分析您的代码库以掌握完整上下文。
  • Plan and execute multi-step solutions.
    规划并执行多步骤解决方案。
  • Run commands or tests.
    执行命令或运行测试。
  • Reach out to external tools for specialized tasks.
    调用外部工具完成专业任务。
  • Suggest architectural improvements.
    提出架构改进建议。
  • Run and refine its own work through an agentic loop, including planning, applying changes, testing, and iterating.
    通过代理循环(包括规划、应用变更、测试和迭代)来运行并优化自身工作。

Rather than just responding to requests, agent mode actively works toward your goal. You define the outcome, and it determines the best approach—seeking feedback from you as needed, testing its own solutions, and refining its work in real time. And as it operates, you can see its reasoning, decision-making process, and the tools it uses.
与仅响应请求不同,代理模式会主动为实现您的目标而努力。您只需定义预期结果,它就能自主确定最佳实现路径 —— 在需要时寻求您的反馈、测试自行提出的解决方案并实时优化工作成果。整个过程中,您可清晰查看其推理逻辑、决策过程及所使用的工具。

Whether you want Copilot to analyze your code base, propose file edits, or run tests, agent mode allows Copilot to complete all the necessary subtasks on its own. 
无论是分析代码库、提议文件修改还是运行测试,代理模式都能让 Copilot 独立完成所有必要的子任务。

On top of that, agent mode enables Copilot to quickly recognize errors and fix them automatically. 
此外,代理模式还能使 Copilot 快速识别错误并自动修复。

Here’s how agent mode compares to some of our other AI coding tools: 
以下是代理模式与我们其他 AI 编程工具的对比情况:

Tool 工具

What it is 功能说明

Agent mode 代理模式

A mode where Copilot is capable of iterating on its own code, recognizing errors, and fixing them automatically
Copilot 能够自主迭代代码、识别错误并自动修复的工作模式

GitHub Copilot coding agent
GitHub Copilot 编程代理

An autonomous SWE agent that asynchronously works on your behalf to do everything from resolving issues to solving for human feedback 
一种自主的软件工程代理,可异步代表您工作,从解决问题到处理人类反馈无所不包

Code completion 代码补全

A Copilot feature that offers autocomplete-style suggestions in supported IDEs 
Copilot 的一项功能,在支持的 IDE 中提供自动补全式建议

How does agent mode in GitHub Copilot work?
GitHub Copilot 的代理模式如何工作?#

Flowchart diagram illustrating how a user interacts with Copilot, which communicates with a machine, workspace, and tools, all connected through a loop involving a large language model (LLM).

At its core, agent mode works as an orchestrator of several different tools and variables (e.g., your prompt and workspace) through a system prompt that tells Copilot to keep iterating on its own output until it reaches a final state. 
代理模式的核心是作为一个协调器,通过系统提示将多种工具和变量(如您的提示和工作区)组织起来,指示 Copilot 持续迭代其输出直至达到最终状态。

When you send a natural-language prompt to Copilot agent mode, it’s augmented by our backend system prompt. This includes your query, a summarized structure of the workspace, machine context, and tool descriptions.
当您向 Copilot 代理模式发送自然语言提示时,我们的后端系统提示会对其进行增强。这包括您的查询、工作区结构摘要、机器上下文以及工具描述。

Here’s a breakdown of what happens when you use Copilot agent mode: 
以下是使用 Copilot 代理模式时的运作流程分解:

  • You prompt Copilot with clear requirements on the end result you want.
    你向 Copilot 明确提出期望的最终结果要求。
  • Copilot parses the question and asks an AI language model how to resolve the task, then begins working.
    Copilot 解析问题后,会询问 AI 语言模型如何解决该任务,然后开始工作。
  • Copilot monitors the first iteration for errors and determines how to fix them.
    Copilot 会监控首次迭代中的错误,并确定如何修复它们。
  • Agent mode autonomously uses various tools to get to the end result. 
    代理模式能自主运用多种工具来达成最终结果。

After it runs commands and applies edits, agent mode works to detect syntax errors, terminal output, test results, and build errors. Based on the results, it then determines how to course-correct, whether that’s by making additional edits, terminal commands, or performing tool calls.
在运行命令并应用编辑后,代理模式会检测语法错误、终端输出、测试结果和构建错误。根据这些结果,它会决定如何进行修正,无论是通过额外编辑、终端命令还是执行工具调用。

The LLM has an ever-expanding set of tools to call, each with capabilities that help Copilot complete the task—and you’re in charge of which tools you want agent mode to use. Each tool, such as read_file, edit_file, and run_in_terminal, gives Copilot detailed instructions on how and when to use it. These tools allow Copilot to search your workspace, read file contents, run terminal commands, get errors from the editor and apply proposed changes, and more.
LLM 拥有不断扩展的可调用工具集,每个工具都能帮助 Copilot 完成任务 —— 而您可自主选择代理模式使用哪些工具。诸如 read_fileedit_filerun_in_terminal 等每个工具,都会向 Copilot 提供详细的使用时机和方法说明。这些工具使 Copilot 能够搜索您的工作区、读取文件内容、运行终端命令、从编辑器获取错误并应用建议更改等。

You’re not limited to just built-in tools. You can extend agent mode’s capabilities by installing more specialized tools from Model Context Protocol (MCP) servers or extensions. MCP is an open standard that enables AI models to interact with external tools and services through a unified interface. We recently announced the GitHub MCP server, which allows you to:
您不仅限于使用内置工具。通过从模型上下文协议(MCP)服务器或扩展安装更专业的工具,您可以扩展代理模式的功能。MCP 是一个开放标准,使 AI 模型能够通过统一接口与外部工具和服务交互。我们最近发布了 GitHub MCP 服务器,它允许您:

  • Automate GitHub workflows and processes.
    自动化 GitHub 工作流和流程。
  • Extract and analyze data from GitHub repositories.
    从 GitHub 仓库中提取并分析数据。
  • Build AI-powered tools and applications that interact with GitHub’s ecosystem.
    构建与 GitHub 生态系统交互的 AI 驱动工具和应用程序。

Combining the power of agent mode and MCP means that the LLM’s knowledge expands even further once connected to your services and data sources. ✨
结合智能代理模式与 MCP 的强大功能,意味着 LLM 的知识库在连接到您的服务和数据源后将得到进一步扩展。✨

What can I do with GitHub Copilot agent mode? What are some use cases?
GitHub Copilot 代理模式能做什么?有哪些使用场景?#

Agent mode brings an agentic workflow to GitHub Copilot, offering real-time, synchronous help across any number of tasks in your workflows. 
代理模式为 GitHub Copilot 引入了智能化工作流,可在您的工作流程中实时同步地协助处理任意数量的任务。

Whether you let the agent take the idea and run with it, or you lead it each step of the way and control the path, you’re in the driver’s seat with Copilot as your, well, copilot.  
无论您是让代理自主执行想法,还是逐步引导并控制其路径,您始终掌握着主导权,而 Copilot 正如其名 —— 始终作为您的副驾驶。

In my personal experience, agent mode has been a game-changer for starting small projects and proof-of-concepts from scratch. When I needed to modernize our open source history visualization scripts, I put agent mode to the test with both GPT-4o and Claude 3.7 models. The results were remarkable—it transformed our basic matplotlib histograms into sophisticated, SVG-based animated line charts with minimal guidance. What truly impressed me was seeing Copilot produce a perfect SVG histogram on its first attempt. This intelligent assistance not only accelerates development but has fundamentally transformed how I approach both prototyping and refactoring.
根据我的个人经验,代理模式彻底改变了从小型项目和概念验证起步的方式。当我需要现代化我们的开源历史可视化脚本时,我同时使用 GPT-4o 和 Claude 3.7 模型测试了代理模式。结果令人惊叹 —— 仅需少量指导,它就将基础的 matplotlib 直方图转化成了精致的基于 SVG 的动画折线图。最让我印象深刻的是 Copilot 首次尝试就生成了完美的 SVG 直方图。这种智能辅助不仅加速了开发进程,更从根本上改变了我对原型设计和代码重构的思维方式。

Zhe-You Liu, Apache Airflow Committer
刘哲有,Apache Airflow 提交者

Here are some ways we’ve seen developers inside and outside GitHub use agent mode:
以下是我们观察到的 GitHub 内外开发者使用代理模式的一些方式:

  • Refactoring code  重构代码
  • Migrating a project to another programming language or to another tech stack
    将项目迁移至另一种编程语言或技术栈
  • Writing tests  编写测试
  • Modernizing legacy code (maybe so you don’t have to learn an outdated language)
    现代化改造遗留代码(或许这样你就不必学习过时的编程语言)
  • Autofixing code gen errors
    自动修复代码生成错误
  • Adding new features to an application
    为应用程序添加新功能
  • Prototyping a new app based on a functional spec or UI sketch
    基于功能规格或 UI 草图原型设计新应用
  • Implementing non-functional requirements or boilerplate code
    实现非功能性需求或样板代码
  • Scoping and planning the work for implementing a new feature 
    规划并确定实现新功能的工作范围
  • Non-code generation tasks, like documentation
    非代码生成任务,例如文档编写

One important thing to note: Copilot is powered by LLMs, which are nondeterministic, and that means its suggestions may differ even with the same prompt and context.
需要注意的一点是:Copilot 由 LLMs 驱动,这些模型具有非确定性特征,这意味着即使使用相同的提示和上下文,其建议也可能有所不同。

How do I start using agent mode?
如何开始使用代理模式?#

Open the Copilot Chat view in VS Code and select agent from the chat mode dropdown list. You can also preview it in Visual Studio.
在 VS Code 中打开 Copilot Chat 视图,从聊天模式下拉列表中选择代理模式。您也可以在 Visual Studio 中预览此功能。

Integrated into the chat experience in VS Code, agent mode has access to your entire workspace and developer environment, so it has proper context to accurately accomplish your requests. To extend agent mode’s powers, select the tools button to configure or add tools.
集成在 VS Code 的聊天体验中,代理模式可访问您的整个工作区和开发环境,因此具备准确完成请求所需的上下文。要扩展代理模式的功能,请选择工具按钮进行配置或添加工具。

Agent mode is powered by your choice of models. You can choose which model to use from the model dropdown list.
代理模式由您选择的模型驱动。您可以通过模型下拉列表选择要使用的模型。

Agent mode is powerful, but you can extend its capabilities by combining it with other features in GitHub Copilot. For instance, you can give Copilot custom instructions so all of its responses fit your day-to-day coding practices, tools, and developers workflows. 
代理模式功能强大,但通过与 GitHub Copilot 的其他特性结合使用,您可以进一步扩展其能力。例如,您可以为 Copilot 提供自定义指令,使其所有响应都能契合您的日常编码实践、工具和开发工作流程。

At GitHub, we often use custom instructions to give Copilot specific testing frameworks to use, as well as guardrails, frameworks, and instructions for unit testing. This allows you to customize how Copilot codes for you in agent mode, similar to giving instructions to one of your peers. 
在 GitHub,我们经常使用自定义指令为 Copilot 指定测试框架,同时设置单元测试的防护机制、框架和指导原则。这使您能够定制 Copilot 在代理模式下的编码方式,就像给团队成员下达指令一样。

You can also use other Copilot Chat modes, like edit mode and ask mode. 
您也可以使用其他 Copilot Chat 模式,例如编辑模式和提问模式。

Mode 模式

What you can do with it
它的用途

A use case 一个应用场景

Edit mode 编辑模式

Easily make edits across multiple files in your codebase.
轻松在代码库中跨多个文件进行编辑。

Apply code edits directly in your project for implementing a new feature, fixing a bug, or refactoring code.
直接在项目中应用代码修改,实现新功能、修复错误或重构代码。

Ask mode 询问模式

Ask Copilot questions for a better understanding of your codebase or technology concepts.
向 Copilot 提问,以便更好地理解您的代码库或技术概念。

Learn how a piece of code works, brainstorm ideas for software, or discover new technologies.
了解一段代码的工作原理,为软件构思创意,或探索新技术。

Agent mode 代理模式

Start an agentic, autonomous coding workflow that delivers your desired result with minimal guidance.
启动一个自主的智能编码工作流程,只需少量指导即可实现预期结果。

Implement high-level requirements for a new feature or project through agent mode, which identifies and applies necessary changes automatically.
通过代理模式实现新功能或项目的高层需求,该模式会自动识别并应用必要的更改。

Take this with you
随身携带这份指南#

Like working with any other developer, the more context you give and the more specific you are about your intended outcome, the better results you’ll get from GitHub Copilot—and that’s particularly true with agent mode. It needs the right tools to do the right work, but by feeding agent mode custom instructions to tailor it to your coding preferences or extending its capabilities via MCP integrations, it can fit your specific style of building software. 
与任何其他开发者合作一样,你提供的上下文越丰富、对预期结果的描述越具体,从 GitHub Copilot 获得的效果就越好 —— 这一点在代理模式下尤为明显。它需要合适的工具来完成正确的工作,但通过为代理模式提供自定义指令来适配你的编码偏好,或是通过 MCP 集成扩展其能力,它就能完美契合你特定的软件开发风格。

As with anything powered by LLMs, agent mode’s suggestions benefit from having you in the pilot’s seat to review code, and make sure things work as expected. But what’s so remarkable about agent mode is that you can use it exactly the way you want. It’s your peer programmer, which means that if you want to use it to build a prototype app, work with an existing codebase, or have it answer questions and automate lower-level parts of your workflow, you can. It’s up to you. Happy building!
与所有由 LLMs 驱动的技术一样,代理模式的建议也需要您这位 "驾驶员" 亲自审查代码,确保一切按预期运行。但代理模式的非凡之处在于,您可以完全按照自己的意愿使用它。它是您的编程伙伴 —— 无论是用来构建原型应用、处理现有代码库,还是解答问题并自动化工作流中的基础环节,都取决于您的需求。祝您编码愉快!

原文链接:

https://github.blog/ai-and-ml/github-copilot/agent-mode-101-all-about-github-copilots-powerful-mode/

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.