Thursday, June 26, 2025

What is Agent Mode in Visual Studio code with Co-Pilot

Why use agent mode?

Agent mode is optimized for making autonomous edits across multiple files in your project. It is particularly useful for complex tasks that require not only code edits but also the invocation of tools and terminal commands. You can use agent mode to:


Refactor parts of your codebase, such as "refactor the app to use a Redis cache".

Plan and implement new features, such as "add a login form to the app using OAuth for authentication".

Migrate your codebase to a new framework, such as "migrate the app from React to Vue.js".

Generate an implementation plan for a complex task, such as "create a meal-planning web app using a Swift front-end and a Node.js back-end".

Define a high-level requirement, such as "add social media sharing functionality".

Agent mode is particularly useful for coding tasks when you have a less well-defined task that might also require running terminal commands and tools. Agent mode autonomously determines the relevant context and tasks to accomplish the request. It can also iterate multiple times to resolve intermediate issues, such as syntax errors or test failures.


Examples are:


Enter your prompt for making edits in the chat input field and select Send (Enter) to submit it.


You can specify a high-level requirement, and you don't have to specify which files to work on. In agent mode, the AI determines the relevant context and files to edit autonomously.


Experiment with some of these example prompts to get started:


Create a meal-planning web app using React and Node.js

Add social media sharing functionality

Replace current auth with OAuth


Agent mode might invoke multiple tools to accomplish different tasks. Optionally, select the Tools icon to configure which tools can be used for responding to your request.


If your project has configured tasks in tasks.json, agent mode tries to run the appropriate tasks. For example, if you've defined a build task, agent mode will run the build task before running the application. Enable or disable running workspace tasks with the github.copilot.chat.agent.runTasks setting.



Copilot detects issues and problems in code edits and terminal commands and will iterate and perform additional actions to resolve them.

Enable the github.copilot.chat.agent.autoFix setting to automatically diagnose and fix issues in the generated code changes. This setting is enabled by default.

For example, agent mode might run unit tests as a result of a code edit. If the tests fail, it uses the test outcome to resolve the issue

Copilot Edits agent mode iterates multiple times to resolve issues and problems. The chat.agent.maxRequests setting controls the maximum number of requests that Copilot Edits can make in agent mode.



As Copilot processes your request, notice that Copilot streams the suggested code edits directly in the editor.

The Chat view shows the list of files that were edited in bold text. The editor overlay controls enable you to navigate between the suggested edits.

Review the suggested edits and accept or discard the suggested edits.

Continue to iterate on the code changes to refine the edits or implement additional features.


Agent mode tools

Agent mode uses tools to accomplish specialized tasks while processing a user request. Examples of such tasks are listing the files in a directory, editing a file in your workspace, running a terminal command, getting the output from the terminal, and more.


Agent mode can use the following tools:


Built-in tools

MCP tools

Tools contributed by extensions

You can view and manage the tools that can be used for responding to a request. Select the Tools icon in the Chat view to view and manage the tools that are available in agent mode.



Based on the outcome of a tool, Copilot might invoke other tools to accomplish the overall request. For example, if a code edit results in syntax errors in the file, Copilot might explore another approach and suggest different code changes.


You can enable or disable the use of agent tools by configuring the chat.extensionTools.enabled setting. Learn how to centrally manage this setting in your organization by checking Centrally Manage VS Code Settings in the enterprise documentation.


Define tool sets

A tool set is a collection of tools that you can use in chat. You can use tool sets in the same way as you would use individual tools. For example, select a tool set with the tools picker in agent mode or reference the tool set directly in your prompt by typing # followed by the tool set name.


Tool sets enable you to group related tools together, making it easier to use them in your chat prompts, prompt files, or custom chat modes. This can be particularly useful when you have many installed tools from MCP servers or extensions.



How to create a new Tool set for Co-Pilot? 


To create a tool set, use the Chat: Configure Tool Sets > Create new tool sets file command in the Command Palette. A tool sets file is a .jsonc file that is stored in your user profile.

A tool set has the following structure:


<tool set name>: name of the tool set, which is displayed in the tools picker and when referencing the tool set in your prompt.

tools: list of tool names that are included in the tool set. The tools can be built-in tools, MCP tools, or tools contributed by extensions.

description: brief description of the tool set. This description is displayed alongside the tool set name in the tools picker.

icon: icon for the tool set, values can be found in the Product Icon Reference.


{

  "reader": {

    "tools": [

      "changes",

      "codebase",

      "fetch",

      "findTestFiles",

      "githubRepo",

      "problems",

      "usages"

    ],

    "description": "description",

    "icon": "tag"

  }

}


Manage tool approvals

When a tool is invoked, Copilot requests confirmation to run the tool. This is because tools might run locally on your machine and perform actions that modify files or data.


In the Chat view, after a tool invocation, use the Continue button dropdown options to automatically confirm the specific tool for the current session, workspace, or all future invocations.


In case you want to auto-approve all tools, you can now use the experimental chat.tools.autoApprove setting. This will automatically approve all tool invocations, and VS Code will not ask for confirmation when a language model wishes to run tools. Bear in mind that with this setting enabled, you will not have the opportunity to cancel potentially destructive actions a model wants to take.


As an enhanced boundary, you might choose to set chat.tools.autoApprove only when connected to a remote environment. You'll want to set this as a remote, rather than user-level, setting. Note that remote environments that are part of your local machine (like dev containers) or that have access to your credentials will still pose different levels of risk.




No comments:

Post a Comment