Use agent mode in VS Code
With chat agent mode in Visual Studio Code, you can use natural language to specify a high-level task, and let AI autonomously reason about the request, plan the work needed, and apply the changes to your codebase. Agent mode uses a combination of code editing and tool invocation to accomplish the task you specified. As it processes your request, it monitors the outcome of edits and tools, and iterates to resolve any issues that arise.
If you don't yet have a Copilot subscription, you can use Copilot for free by signing up for the Copilot Free plan and get a monthly limit of completions and chat interactions.
Prerequisites
- Install the latest version of Visual Studio Code
- Access to Copilot
Use agent mode
In agent mode, Copilot operates autonomously and determines the relevant context for your prompt.
Follow these steps to get started:
-
Make sure that agent mode is enabled by configuring the chat.agent.enabled setting in the Settings editor (requires VS Code 1.99 or later).
-
Open agent mode in VS Code Stable or Insiders.
Alternatively, open the Chat view (⌃⌘I (Windows, Linux Ctrl+Alt+I)) and select Agent from the chat mode selector.
-
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, Copilot 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.
TipYou can also directly reference a tool in your prompt by typing
#
followed by the tool name. You can do this in all chat modes (ask, edit, and agent mode). -
Confirm tool invocations and terminal commands.
Before running a terminal command or non-builtin tool, Copilot requests confirmation to continue. This is because tools might run locally on your machine and perform actions that modify files or data.
Use the Continue button dropdown options to automatically confirm the specific tool for the current session, workspace, or all future invocations. Learn how to manage tool approvals and approve all tool invocations.
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. -
Optionally, verify and edit the tool input parameters before running the tool.
Select the chevron next to the tool name to view its details and input parameters. You can edit the input parameters before running the tool.
-
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.
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.
You can reset the tool confirmations by using the Chat: Reset Tool Confirmations command in the Command Palette.
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.
Accept or discard edits
Copilot lists the files that were edited in the list of the changed files in the Chat view. Files with pending edits also have an indicator in the Explorer view and editor tabs.
With the editor overlay controls, you can navigate between the suggested edits by using the Up () and Down () controls. Use the Keep or Undo button to accept or reject the edits for a given file.
Use the Keep or Undo controls in the editor or Chat view to accept or reject individual or all suggested edits.
With the chat.editing.autoAcceptDelay setting, you can configure a delay after which the suggested edits are automatically accepted. Hover over the editor overlay controls to cancel the auto-accept countdown.
When you close VS Code, the status of the pending edits is remembered. When you reopen VS Code, the pending edits are restored, and you can still accept or discard the edits.
Revert edits
As you're sending requests to make edits to your code, you might want to roll back some of these changes, for example, because you want to use another implementation strategy or because Copilot starts walking down the wrong path when generating edits.
You can use the Undo Last Edit control in the Chat view title bar to revert the last edits and return to the state before sending the last request. After you perform an undo of the last edit, you can redo those edits again by using the Redo Last Edit control in the Chat view title bar.
You can also use the Undo Edits (Delete) control (x icon) when hovering over a request in the Copilot Edits view to revert all edits that were made from that request onwards.
Interrupt an agent mode request
To interrupt an ongoing request, you can either Pause it or Cancel it. When you pause a request, Copilot stops processing the request and waits for your input.
When you pause a request, you can either choose to enter a new prompt, which cancels the current request, or you can choose to resume the current request.
When you cancel a request, Copilot interrupts and ends the active request. You can still review and accept or reject the changes that were made up to that point.
Settings
The following list contains the settings related to agent mode. You can configure settings through the Settings editor (⌘, (Windows, Linux Ctrl+,)).
- chat.agent.enabled: enable or disable agent mode (default:
false
, requires VS Code 1.99 or later) - chat.agent.maxRequests: maximum number of requests that Copilot Edits can make in agent mode (default: 5 for Copilot Free users, 15 for other users)
- github.copilot.chat.agent.runTasks: run workspace tasks when using agent mode in Copilot Edits (default:
true
) - chat.mcp.discovery.enabled: enable or disable discovery of MCP servers configured in other tools (default:
true
) - github.copilot.chat.agent.autoFix: automatically diagnose and fix issues in the generated code changes (default:
true
) - chat.tools.autoApprove (Experimental): automatically approve all tools (default:
false
)
Frequently asked questions
Why would I use agent mode instead of edit mode?
Consider the following criteria to choose between edit mode and agent mode:
- Edit scope: agent mode autonomously determines the relevant context and files to edit. In edit mode, you need to specify the context yourself.
- Task complexity: agent mode is better suited for complex tasks that require not only code edits but also the invocation of tools and terminal commands.
- Duration: agent mode involves multiple steps to process a request, so it might take longer to get a response. For example, to determine the relevant context and files to edit, determine the plan of action, and more.
- Self-healing: agent mode evaluates the outcome of the generated edits and might iterate multiple times to resolve intermediate issues.
- Request quota: in agent mode, depending on the complexity of the task, one prompt might result in many requests to the backend.