The GitHub Blog 03月26日 00:08
Mastering GitHub Copilot: When to use AI agent mode
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文深入探讨了GitHub Copilot的两种核心功能:Copilot Edits和Agent模式,它们分别适用于不同的编码场景。Copilot Edits擅长快速、精准的修改,如重构函数和修复错误;而Agent模式则更适合处理复杂的多文件任务,如分析代码库、提出架构改进建议等。文章通过实际案例,阐述了如何根据需求选择合适的工具,并强调了两者结合使用的重要性,以最大化AI辅助编码的效率。最后,文章还提供了入门指南,帮助开发者快速上手。

💡 Copilot Edits 适用于快速、精确的修改。例如,重构函数、修复bug或跨文件应用一致性更改。这种模式能够保持编码流程的流畅性,适合对现有代码进行局部调整。

🤖 Agent模式 擅长处理复杂、多文件的编码任务。它可以分析代码库、提出架构改进建议,甚至执行终端命令。Agent模式允许开发者提供高层次的指导,AI则负责处理实现细节,开发者可以控制整个过程。

💻 Copilot Chat 窗口是AI交互的中心。开发者可以在这里提问、解释代码、调试问题、生成测试等。通过理解代码上下文,开发者可以更好地选择Edits或Agent模式。

🔄 结合使用Edits和Agent模式,可以提升编码效率。Edits用于快速调整,Agent模式用于处理复杂功能,两者相辅相成,让开发者能够更有效地利用AI辅助编码。

🚀 开发者始终掌握最终控制权。无论是使用Edits还是Agent模式,开发者都可以审查和批准AI的修改建议,确保代码质量和符合预期。

Ever find yourself staring at an AI coding assistant, wondering why it’s not quite nailing what you need? Maybe it’s spitting out code that’s close but not quite right, or you’re stuck wrestling with a problem that spans multiple files, wishing it could just get the bigger picture. Often, when developers hit these snags, it’s less about the tool, and more about knowing how to use it.

So here’s the key question you should ask yourself: “Do I need a quick answer or a thoughtful conversation?” That’s the secret to unlocking AI coding tools like GitHub Copilot.

Because different aspects of Copilot serve different needs, and we’re here to help you discern when is the best time for agent mode and when you should be using Copilot Edits instead. Both are powerhouse Copilot features, built to supercharge your coding, but they shine in different scenarios.

Copilot Edits is your go-to for fast, precise tweaks—think refactoring a function, squashing a bug, or applying consistent changes across files without losing your flow.

Agent mode, on the other hand, steps up as your AI collaborator for thornier, multi-file challenges—analyzing your codebase, proposing architectural fixes, and even running terminal commands while you steer the ship and approve each move.

Figuring out which one fits your needs doesn’t just save time, it turns your AI assistant into a seamless extension of your own coding instincts.

Copilot command center: Your chat window

Before learning more about agent mode and Copilot Edits, it’s essential to understand the Copilot chat window in VS Code—your central hub for AI interactions.

This is where you can:

With the chat window giving you a solid grasp of your code’s context, you’re in the driver’s seat to pick the perfect Copilot tool: Edits or agent mode, for whatever’s next.

Let me take you through a real-world example of how I’ve been using GitHub Copilot to evolve my personal website. It started with a simple idea: create an interactive terminal-style easter egg that showcases my skills in a developer-friendly way.

I began with a basic command processing function that handled a few simple commands:

function processCommand(command) {  try {    if (!command?.trim()) {      return 'Please enter a command. Type "more" for available commands.';    }    const sanitizedCommand = command.toLowerCase().trim();    switch (sanitizedCommand) {      case 'more':        return commands.more;      case 'about':        return commands.about;      case 'skills':        return commands.skills;      case 'projects':        return commands.projects;      case 'contact':        return commands.contact;      default:        return `Command not found: "${command}". Type 'more' for available commands.`;    }  } catch (error) {    console.error('[Terminal] Error processing command:', error);    return 'An error occurred while processing the command.';  }}

Initially, I used Copilot Edits to quickly add new features. For instance, I wanted to add a ‘github’ command to showcase my repositories:

Copilot Edits made targeted changes to the switch statement in the processCommand function and added the new command to the commands object—a perfect example of quick, focused modifications to existing code.

As my terminal interface matured, I wanted to implement several interactive features that would require more comprehensive improvements. To get animation effects, keyboard navigation controls, and an extensible theming system that spanned multiple files to work together seamlessly, I turned to agent mode.

The agent mode advantage

When we designed agent mode, we didn’t want to create a tool that’s a simple AI feature: We wanted to create an AI that could pair with you! Rather than working on specific, limited changes where you might be reinventing the wheel, you’re now providing higher-level direction while the AI tackles the implementation details across multiple files or systems.

That being said, with agent mode, you’re still in control of the process. The AI has more latitude to explore your codebase and suggest comprehensive solutions, but you always review and approve the changes before they’re applied. It’s not about surrendering control, it’s about effectively delegating implementation details while you focus on the bigger picture.

What makes agent mode special:

I reach for agent mode when:

Continuing with my terminal easter egg, let’s say I want to implement a much more extensive upgrade with multiple features, like adding a typing animation effect for responses, command history navigation with up/down arrows, and tab completion for commands. At the same time, I want to create a new TerminalThemes.css file with different color scheme options that users can switch between with a ‘theme’ command.

This is where agent mode truly shines. The task spans multiple files, requires an understanding of the existing codebase, and involves creating entirely new functionality. Here, agent mode would:

    Search through the codebase to understand the terminal implementation. Create the new CSS file for themes. Add typing animation functionality to terminal responses. Implement keyboard handlers for history navigation. Build the tab completion system. Add the theme command to the switch statement. Test the implementation to ensure everything works correctly.

This is the beauty of agent mode: it has a complex understanding of patterns and relationships in different parts of the codebase! Agent mode can ensure that the typing animation did not interfere with existing functionality, check that the history navigation was compatible with the current command processing, and confirm that the theme switching properly modified the UI. It is precisely in this multi-file feature implementation with interlinking components that agent mode can shine compared to the more laser-focused Copilot Edits.

In the below episode of GitHub Checkout, you can see agent mode implementing a complete water consumption tracker feature in an iOS app. It not only writes the code but also builds, runs, and tests the app, all from a single prompt, without the developer needing to touch the editor directly.

The secret: use both together!

After many hours with both tools, here’s my takeaway: It’s not about picking one, or one being better than the other. It’s about wielding them together for different purposes. Copilot Edits and agent mode work well together to augment our coding abilities, whether that’s a more prompt-centric style of development with agent mode, or maintaining granular file edit control via Copilot Edits.

Regardless of which tool you are using, you are still the pilot, steering the AI to supercharge your own productivity. The more context you provide in your prompts, the better results you’ll get—and remember, you always have the final say on any suggested changes.

If you’re just jumping into the world of AI, check out our new Getting started with GitHub Copilot tutorial series, where we walk you through everything from initial setup to advanced techniques. It’s perfect for developers at any skill level who want to quickly become productive with AI-assisted coding.

Happy coding, everyone! 💻✨

How to get started

Want to try these features? Here’s my quick setup guide:

For Copilot Edits:

    Open VS Code and look for the Copilot Chat window. Click the “Edit with Copilot” button to open the Copilot Edits view. Add your relevant files to the working set. Copilot will only make changes to files in this set (unless it’s creating a new file). Type your prompt describing what changes you need. Review the “diff” of all proposed changes before accepting them.

For agent mode:

    Make sure you’re using VS Code version 1.99 or higher (as of original publish date, available in VS Code Insiders). Switch from “Edit” to “Agent” mode. Type your prompt, describing the complex task or feature you want to implement. Agent mode will work autonomously, but still require your approval for changes. For best results, consider using custom instructions to personalize how agent mode works with your codebase.

Try GitHub Copilot free
Ready to automate your dependency management with AI? Learn more about GitHub Copilot for Business or start your free trial of GitHub Enterprise today.

The post Mastering GitHub Copilot: When to use AI agent mode appeared first on The GitHub Blog.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

GitHub Copilot Copilot Edits Agent模式 AI辅助编码 VS Code
相关文章