Agent Mode

With agent mode, you can ask VS Code to perform entire software engineering tasks. These could include asking Copilot to setup entire projects and install relevant packages, edit code, and run projects and code. You will interact with Copilot in agent mode using the same chat interface we discussed in the previous chapter. To use agent mode, you will need to switch the mode by pressing Control+., or getting to the mode popup box by pressing Tab from the chat input edit box.

Once you enter your query and press Enter, VS Code informs you that the chat request is sent by playing the [list signal from prev chapter]. Copilot informs you that it is working on your request by [list signal from prev chapter]. Copilot indicates that the response is received by [fill signal from prev chapter].

The experience may differ from chat based on the nature of your request. Copilot in agent mode will provide final output of 2 major types: explanations of what it did, and the actual changes. Copilot may also require you to give it permission to run specific commands as it works on your task. I will walk you through working with the different types of intermediate and final outputs.

Confirming Terminal and Other Actions

Copilot asks permissions when it needs to perform actions on your behalf on your computer. Copilot indicates the need for you to review and approve actions by playing the “Chat user action required” signal and announcement. When this happens, you can review the action in question by going to the accessible view. Exit the accessible view by pressing Escape and press Control+Enter to approve or Alt+Backspace to reject. You will continue to hear the progress signal while the system is waiting for your input. If the requested action is a terminal command, you will hear the status of the command execution through the audio signals indicating success and failure. If the command fails, Copilot tries to execute a different command and may ask you to approve its action again.

Signal indicating that Copilot needs you to review and confirm an action it wants to take

Reviewing Final Output

You can review Copilot’s final output using the accessible view. Copilot will not include all the code it generates here; it instead provides the explanations in this view and indicates that it has made changes. You can also review what Copilot is doing by invoking the accessible view before it completes the task if you want to understand what the agent is doing.

Reviewing Code Changes

Depending on the type of task, agent mode may edit existing code, or create new files and add code to these new files. Every file that agent mode modifies is opened and available for you to review. You can switch between these files by pressing Control+Tab. VS Code indicates that you are in a file with Copilot modifications by playing the “chat edit modified file” signal when you switch to it. Once you are in a file with Copilot modifications, you can review its contents as you would any other file. As you navigate through the file, you will be alerted to the modifications made by Copilot through “Diff line deleted,” “Diff line inserted,” and “Diff line modified” files. For example, if you are reviewing a new file created by Copilot, you may hear each line with the “Diff line modified” sound. At the time of writing this tutorial, VS Code has a bug that causes it to play the chat edit modified files signal even after accepting or rejecting all copilot modification files. We, however, expect this to be resolved in the next release of VS Code.

Chat edit Modified File signal indicating the currently focused editor is showing a file containing Copilot Modifications.
Diff line inserted signal indicating new code has been added
Diff line deleted signal indicating code has been removed
Diff line modified signal indicating existing code has been changed

You can accept a code change by pressing Control+Y, and reject by pressing Control+N. Once you act on a change, your cursor automatically moves to the next modification on that file. You can accept all changes made by Copilot by pressing Control+Shift+Y and reject all of them by pressing Control+Shift+N. You will need to save your file once you finish acting on all changes.

audio signal indicating that you kept (accepted) the edits made by Copilot.
audio signal indicating that you undid (rejected) the edits made by Copilot.

Try it Yourself

  1. Open the read_exampleCode.py file.
  2. Open Copilot chat by pressing Control+Alt+I.
  3. Switch to agent mode by pressing Control+Shift+I.
  4. Ask Copilot to simplify the code.

Practice Yourself: Creating a Flask Website

  1. Open a new folder.
  2. Open chat and switch to agent mode.
  3. Ask Copilot to create a simple Flask website for a blog.

Ask yourself the following questions as you reflect on this practice activity:

  1. What was the exact prompt you gave Copilot?
  2. Did Copilot give you a working Flask app?
  3. What steps did Copilot take?
  4. What user actions did you have to approve?
  5. If there were a setting to auto-approve user actions, would you enable it? Why/why not?