|
| 1 | +## Step 1: Hello GitHub Copilot agent mode |
| 2 | + |
| 3 | +Welcome to your **"Build applications with GitHub Copilot agent mode"** exercise! :robot: |
| 4 | + |
| 5 | +In this exercise, you will be using GitHub Copilot agent mode to build an application that tracks your fitness goals and progress. 🏋️♂️🏃♀️💪 |
| 6 | + |
| 7 | +### What is GitHub Copilot agent mode? |
| 8 | + |
| 9 | +Copilot agent mode can create apps from scratch, perform refactorings across multiple files, write and run tests, and migrate legacy code to modern frameworks. It can automatically generate documentation, integrate new libraries, or help answer questions about a complex codebase. Copilot agent mode helps you be super-productive by having an AI collaborator that understands the workspace. It can orchestrate your inner development flow while keeping you in control. |
| 10 | + |
| 11 | +Copilot agent mode operates in a more autonomous and dynamic manner to achieve the desired outcome. To process a request, Copilot loops over the following steps and iterates multiple times as needed: |
| 12 | + |
| 13 | +Determines the relevant context and files to edit autonomously. |
| 14 | +Offers both code changes and terminal commands to complete the task. For example, Copilot might compile code, install packages, run tests, and more. |
| 15 | +Monitors the correctness of code edits and terminal command output and iterates to remediate issues. |
| 16 | + |
| 17 | +> [!TIP] |
| 18 | +> You can learn more about GitHub Copilot agent mode in the [Use agent mode documentation](https://code.visualstudio.com/docs/copilot/copilot-edits#_use-agent-mode-preview). |
| 19 | +
|
| 20 | +> [!NOTE] |
| 21 | + Copilot agent mode is a preview feature available in [Visual Studio Code Insiders](https://code.visualstudio.com/insiders). |
| 22 | + |
| 23 | +Your most common interactions with Gitub Copilot will likely be: |
| 24 | + |
| 25 | +- **Inline suggestions**: As you type, Copilot uses the nearby context to suggest code directly in your editor. This will be a familiar interaction if you have used code completion tools like [Intellisense](https://code.visualstudio.com/docs/editor/intellisense), except that the completions may be entire functions. |
| 26 | +- **Copilot Chat**: A dedicated chat panel that lets you ask coding related questions. This will feel familiar if you have used online AI assistant chats. The big difference however, is that your project files will provide automatic context to provide tailored responses. |
| 27 | +- **Copilot Edits**: Similar to Copilot Chat, but less conversational and more big picture or goal oriented. |
| 28 | +- **Copilot agent mode**: Operates in a more autonomous and dynamic manner to achieve the desired outcome. To process a request, Copilot loops over the following steps and iterates multiple times as needed: |
| 29 | + - Determines the relevant context and files to edit autonomously. |
| 30 | + - Offers both code changes and terminal commands to complete the task. For example, Copilot might compile code, install packages, run tests, and more. |
| 31 | + - Monitors the correctness of code edits and terminal command output and iterates to remediate issues. |
| 32 | + |
| 33 | +> [!TIP] |
| 34 | +> You can learn more about current and preview features in the [GitHub Copilot Features](https://docs.github.com/en/copilot/about-github-copilot/github-copilot-features) documentation. |
| 35 | +
|
| 36 | +> [!TIP] |
| 37 | +> You can also select different [models](https://docs.github.com/en/github-models) and [extensions](https://github.com/features/copilot/extensions), but that's for a different lesson! |
| 38 | +
|
| 39 | +Before we get started on developing an application in GitHub Copilot agent mode, we have to configure our development environment. |
| 40 | +Fortunately, this has been bootstrapped for us with a pre-configured [Codespace](https://github.com/features/codespaces). |
| 41 | + |
| 42 | +This development environment includes: |
| 43 | + |
| 44 | +- React.js frontend. |
| 45 | +- Django REST Framework backend. |
| 46 | +- MongoDB database. |
| 47 | +- The Node.js runtime. |
| 48 | +- The Python runtime. |
| 49 | + - forwardPorts |
| 50 | + - 3000, // React default port |
| 51 | + - 8000, // Django default port |
| 52 | + - 27017 // MongoDB default port |
| 53 | +- VS Code extensions: |
| 54 | + - GitHub Copilot/Copilot Chat insiders |
| 55 | + - Python |
| 56 | + - Markdown linter |
| 57 | +- [VS Code](https://code.visualstudio.com/) launch settings to start your application in debug mode. |
| 58 | + |
| 59 | +### :keyboard: Activity: Getting to know your GitHub Copilot agent mode development environment |
| 60 | + |
| 61 | +1. Right-click the below button to open the **Create Codespace** page in a new tab. |
| 62 | + |
| 63 | + [](https://codespaces.new/{{full_repo_name}}?quickstart=1) |
| 64 | + |
| 65 | + - The free tier of Codespaces that comes with all GitHub accounts is fine, assuming you still have minutes available. |
| 66 | + - The default Codespace settings are fine. |
| 67 | + |
| 68 | +1. Confirm the **Repository** field is your copy of the exercise, not the original, then click the green **Create Codespace** button. |
| 69 | + |
| 70 | + - ✅ Your copy: `/{{{full_repo_name}}}` |
| 71 | + - ❌ Original: `/continuous-copilot/build-applications-w-copilot-agent-mode` |
| 72 | + |
| 73 | +1. Wait a moment for Visual Studio Code to load. |
| 74 | + |
| 75 | +1. Before we continue let's take a moment to familiarize ourselves with the project folder. |
| 76 | + |
| 77 | + - The left navigation bar is where you can access the file explorer, debugger, and search. |
| 78 | + - The lower panel (Ctrl+J) shows the debugger output, allows running terminal commands, and allows configuring the web service ports. |
| 79 | + - Our docs folder contains the another sample application repository that will give Copilot agent mode context to build your application. More on that in the next steps! |
| 80 | + |
| 81 | +1. At the top of VS Code, locate and click the Copilot icon to open a Copilot Chat panel. |
| 82 | + |
| 83 | +<img width="150" alt="image" src="https://github.com/user-attachments/assets/5e64db46-95cb-415d-badc-b6b8677f10c1" /> |
| 84 | + |
| 85 | +1. If this is your first, time using GitHub Copilot, you will have to accept the usage terms to continue. |
| 86 | + - Click the **Accept** button to continue. |
| 87 | + - If you are using Copilot Chat for the first time, you will also have to accept the usage terms to continue. |
| 88 | + - Click the **Accept** button to continue. |
| 89 | + |
| 90 | +### :keyboard: Activity: Use Copilot to help remember a terminal command 🙋 |
| 91 | + |
| 92 | +Great work! Now that we are familiar with the app and we know it works, let's ask copilot for help starting a branch so we can do some customizing. |
| 93 | + |
| 94 | +1. If not already there, return to VS Code. |
| 95 | + |
| 96 | +1. In the bottom panel, select the **Terminal** tab. On the right side, click the plus `+` sign to create a new terminal window. |
| 97 | + |
| 98 | + > **Note:** This will avoid stopping the existing debug session that is hosting our web application service. |
| 99 | +
|
| 100 | +1. Within the new terminal window, use the keyboard shortcut `Ctrl + I` (windows) or `Cmd + I` (mac). |
| 101 | + |
| 102 | +1. Let's ask Copilot to help us remember a command we have forgotten: creating a branch and publishing it |
| 103 | + |
| 104 | + > <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt** |
| 105 | + > |
| 106 | + > ```prompt |
| 107 | + > Hey copilot, how can I create and publish a new Git branch? |
| 108 | + > ``` |
| 109 | +
|
| 110 | + > **Tip:** This is a simple example, but Copilot is great at providing more tailored commands that might involve loops, pattern matching, file modification, and more! Don't be afraid to ask Copilot for a suggestion. Just remember it is a suggestion and you should always verify it first to be safe. |
| 111 | +
|
| 112 | +1. Copilot probably gave us a command like the following. Rather than manually modify it, let's respond back to tell Copilot to use a particular name. |
| 113 | +
|
| 114 | + ```bash |
| 115 | + git checkout -b {new_branch_name} |
| 116 | + git push -u origin {new_branch_name} |
| 117 | + ``` |
| 118 | +
|
| 119 | + > <img width="13px" src="https://github.com/user-attachments/assets/98fd5d2e-ea29-4a4a-9212-c7050e177a69" /> **Prompt** |
| 120 | + > |
| 121 | + > ```prompt |
| 122 | + > Awesome! Thanks, Copilot! Let's use the |
| 123 | + > branch name "build-octofit-app". |
| 124 | + > ``` |
| 125 | +
|
| 126 | + > **Tip:** If Copilot doesn't give you quite what you want, you can always continue explaining what you need. Copilot will remember the conversation history for follow-up responses. |
| 127 | +
|
| 128 | +1. Now that we are happy with the command, press the `Run` button to let Copilot run it for us. No need to copy and paste! |
| 129 | +
|
| 130 | +1. After a moment, look in the VS Code lower status bar, on the left, to see the active branch. It should now say `build-octofit-app`. If so, you are all done with this step! |
| 131 | +
|
| 132 | +## Next step |
| 133 | +
|
| 134 | +Now that your branch is pushed to GitHub, let's continue on to the next step Step 2: Application Initial Setup - {{{next_step_file}}}. |
0 commit comments