技术速递|使用 GitHub Copilot Agent Mode 进行编程

B站影视 韩国电影 2025-04-10 22:42 2

摘要:GitHub Copilot 持续发展,从最初的代码补全、生成、优化功能,到通过对话交互提升 AI 代码质量的 GitHub Copilot Chat,再到能够基于项目中多个文件的关联进行协同创作、调试和调整的 GitHub Copilot Edit Mode

M

作者:卢建晖 - 微软高级云技术布道师

翻译/排版:Alan Wang

GitHub Copilot 持续发展,从最初的代码补全、生成、优化功能,到通过对话交互提升 AI 代码质量的 GitHub Copilot Chat,再到能够基于项目中多个文件的关联进行协同创作、调试和调整的 GitHub Copilot Edit Model,最终发展到今天的 GitHub Copilot Agent Mode——通过 AI Agent 完成项目工程开发。GitHub Copilot 结合大语言模型(LLM),打造出一种基于 AI Agent 的智能编程方案,让非计算机专业人士也能真正参与到项目开发中来。本文将聚焦 GitHub Copilot Agent Mode,带你深入了解这种智能编程的新方式。

成为一名游戏开发者

我相信每个人都会玩电子游戏,但如果你想亲自创作一款游戏,那就会有一定的门槛。现在,让我们通过 GitHub Copilot Agent Mode 来创建你的第一个在线游戏。

在 GitHub Copilot 中选择 Agent 模型,选用 Claude 3.7 Sonnet,并在对话框中输入以下内容:

Please help me generate an HTML5 basketball shooting mobile game according to the following requirements 1. All elements of the game are generated with svg 2. Players need to adjust the strength to complete the shot on the service line 3. The basket is directly above 4. There are 3 levels, and you need to complete the shot within a limited time. Each time you shoot 10 shots, and you can advance to the next level after you make 8 shots. The time for each level is decreasing, such as 30 seconds for the first level, 20 seconds for the second level, and 10 seconds for the third level 5. Each player needs to enter his name before entering the game 6. You can play again if you fail to pass the level

我们可以在 3 到 5 分钟内基于 HTML5 生成一个投篮游戏。

在 GitHub Copilot Agent Mode 中尝试更多模型

GitHub Copilot 为用户提供了足够多的世界级编程模型可供选择,例如 Claude 3.5 / 3.7、GPT 4.5 / 4o、Gemini 1.5 等。针对不同的开发场景,尤其是在企业应用场景中,或是需要本地化的 Ollama 或第三方接口(如 OpenRouter、Azure OpenAI Service、OpenAI 等)的模型,GitHub Copilot 现在也支持更多模型的接入。我们可以在选择模型时,通过 “Manage Models(管理模型)” 添加更多第三方模型。

点击后,你可以从不同来源选择模型。

这里我们选择 OpenRouter(如果你还没有 OpenRouter,可以前往 https://openrouter.ai/ 注册并获取 API Key)。如果是第一次使用,需要输入 API Key;否则将直接显示 OpenRouter 的模型列表,如下图所示:

我们可以尝试使用最新的 DeepSeek V3 0324 作为 GitHub Copilot Agent Mode 模型。

接下来,我们将尝试使用该模型进行开发。

Create a private task management system through Python Flask. The frontend is saved in the templates folder. It uses HTML5 + JS + CSS. The backend uses JSON to save data.

MCP 扩展 GitHub Copilot Agent Mode 的企业项目能力

在企业级编程中,AI 的作用不仅仅是生成代码,还需要能够连接到不同的工具,如数据库、云服务、DevOps 管理等。我们可以通过 MCP 协议连接这些工具,并结合大语言模型(LLM),完成更强大的企业级场景应用。

GitHub Copilot Agent Mode 支持 MCP 服务器,可以连接不同的 MCP 服务。我们可以设想一个有趣的场景:制作一个项目汇报的 PPT。过去你可能需要投入人力和时间去完成,但现在通过 GitHub Agent Mode 结合 MCP,就能快速完成这项任务。下面我来为你详细说明。

我们需要一个 PPT 的 MCP 服务。此时,我们可以使用 https://github.com/microsoft/semanticworkbench/tree/main/mcp-servers/mcp-server-office 中的 Office MCP 服务。只需在命令行中执行以下命令,即可通过本地 STDIO 或远程 SSE 启动 SSE 连接:

uv run -m mcp_server.start --transport sse --port 25566

启动成功后,进入 GitHub Copilot Agent Mode 配置 MCP,如下图所示:

打开配置文件,添加 MCP 服务器。

"mcp-server-office": { "url": "http://127.0.0.1:25566/sse", "type": "sse" }

我们尝试下载 Semantic Kernel,然后使用 DeepSeek V3 0324 对项目进行分析,并通过以下提示生成一个 10 页的 PPT:

Please analyze the project and make a 10-page ppt(请分析该项目并制作一个 10 页的 PPT)。

在 Agent Mode 中,我们可以通过 DeepSeek V3 0324 分析 Semantic Kernel 项目,并调用 PPT MCP 服务来完成简单的 PPT 内容创作。这只是一个小示例,当然你也可以更好地利用 MCP 来创建更多面向企业的应用。

相关资源

了解 GitHub Copilot Agent Mode

学习 GitHub Copilot Agent

来源:opendotnet

相关推荐