|
| 1 | +--- |
| 2 | +title: "Lesson 2 - Running your first agent session" |
| 3 | +description: "Start your first agent session in the GitHub Copilot app, make a small change to the game cards, and merge it as your first pull request." |
| 4 | +--- |
| 5 | + |
| 6 | +In the previous lesson you toured the workspace and used a quick chat. Now it's time to start an **agent session** and make your first change to the project. You'll keep it small: the games already have a star rating in their data, but the game cards on the home page don't show it yet. You'll ask the agent to surface it, review the change, and merge it as your first pull request. |
| 7 | + |
| 8 | +In this lesson, you will: |
| 9 | + |
| 10 | +- start an agent session and learn how a session is structured. |
| 11 | +- ask the agent to make a small, focused change to the project. |
| 12 | +- review the change in the workspace diff view. |
| 13 | +- run the app locally to confirm the change in the browser. |
| 14 | +- open and merge your first pull request. |
| 15 | + |
| 16 | +## Scenario |
| 17 | + |
| 18 | +Each game in Tailspin Toys can have a star rating, and it already appears on the game details page. The game cards on the home page, though, only show the title, category, publisher, and description. As a warm-up, you'll have the agent display the existing rating on each card — a tiny, self-contained change that's perfect for your first session. |
| 19 | + |
| 20 | +## Anatomy of a session |
| 21 | + |
| 22 | +A **session** is a conversation with an agent that runs in its own isolated workspace. Every session gets a **dedicated git worktree and branch**, which is what lets you run several sessions at once — one adding a feature, another fixing a bug — without their changes colliding. Your sessions appear in the sidebar grouped by repository; select any one to switch to it. |
| 23 | + |
| 24 | +Inside a session you'll see three things: the **conversation** with the agent, the agent's **tool activity** as it explores and edits files, and the list of **changed files** with their diffs. |
| 25 | + |
| 26 | +## Start a session and request our change |
| 27 | + |
| 28 | +Let's start a new session to begin exploring the project and implementing our feature. In a [prior lesson][prior-lesson] you added your project from its GitHub repository. We'll create a new session for that repository and request our change. |
| 29 | + |
| 30 | +1. Return to (or open) the GitHub Copilot app. |
| 31 | +2. Select the **Home screen**. |
| 32 | +3. Ensure `tailspin-toys` is selected for the repo. |
| 33 | + |
| 34 | +  |
| 35 | + |
| 36 | +4. Use the following prompt to request the change: |
| 37 | + |
| 38 | + ```plaintext |
| 39 | + On the game cards, show each game's star rating. The Game type already includes a starRating field — it's a number out of 5, or null when a game hasn't been rated yet. Display it on each card in src/components/GameCard.astro, and when starRating is null show "No rating yet" instead. Keep the change small and don't restructure the card layout. |
| 40 | + ``` |
| 41 | + |
| 42 | +> [!NOTE] |
| 43 | +> Notice how the prompt contained the name of the file for Copilot to update. While it's not required at all to specify which files Copilot should include in its work, pointing it in the right direction both helps Copilot quickly generate code and reduce token usage. |
| 44 | +
|
| 45 | +5. Select <kbd>Enter</kbd> to send the prompt to Copilot. |
| 46 | + |
| 47 | +Copilot app begins work by first creating a new worktree, an isolated copy of the project. It then explores the project, locating the necessary files to update to add the new feature. It will then create the necessary code. You've now added a new feature with Copilot app! |
| 48 | + |
| 49 | +## Review the diff |
| 50 | + |
| 51 | +All AI-generated changes deserve a review before they're merged, even small ones. Let's explore the changes, right here in Copilot app. |
| 52 | + |
| 53 | +1. In the upper right-hand corner of the app, select **Toggle review panel**. This will open the diff screen with all the outstanding changes made by Copilot. |
| 54 | + |
| 55 | +  |
| 56 | + |
| 57 | +2. You should notice code added to `GameCard.astro`, the core file used to display game details. It should be similar to the following — a small block that renders the rating when present and falls back to "No rating yet" when `starRating` is `null`: |
| 58 | + |
| 59 | + ```astro |
| 60 | + {game.starRating !== null ? ( |
| 61 | + <span class="text-xs font-medium px-2.5 py-0.5 rounded bg-amber-900/60 text-amber-300" data-testid="game-rating"> |
| 62 | + ★ {game.starRating} / 5 |
| 63 | + </span> |
| 64 | + ) : ( |
| 65 | + <span class="text-xs font-medium text-slate-500" data-testid="game-rating-empty"> |
| 66 | + No rating yet |
| 67 | + </span> |
| 68 | + )} |
| 69 | + ``` |
| 70 | + |
| 71 | +> [!NOTE] |
| 72 | +> Because Copilot, like all generative AI tools, is probabilistic rather than deterministic, the exact code may vary from the above. But it should be relatively similar. |
| 73 | +
|
| 74 | +## Check the changes |
| 75 | + |
| 76 | +Of course we shouldn't just read the code and assume it works. We should visually test everything as well! To do so we'll need to start the app from the terminal, then confirm everything works. Fortunately there's a terminal button in the upper right that will allow us quick access to the worktree the Copilot app created! |
| 77 | + |
| 78 | +1. In the upper right hand corner of the Copilot app, select **Open** next to the terminal icon. |
| 79 | + |
| 80 | +  |
| 81 | + |
| 82 | +2. Enter the following command in the terminal window to start the web app's dev server: |
| 83 | + |
| 84 | + ```shell |
| 85 | + npm run dev |
| 86 | + ``` |
| 87 | + |
| 88 | +3. Once the server starts (this will just take a moment), open a browser window. |
| 89 | +4. Navigate to http://localhost:4321. |
| 90 | +5. You should now see star ratings on all the games on the landing page! |
| 91 | +6. Return to the terminal window. |
| 92 | +7. Select <kbd>Ctl</kbd>+<kbd>C</kbd> to stop the dev server. |
| 93 | + |
| 94 | +## Open and merge your first pull request |
| 95 | + |
| 96 | +Your change looks good — now it's time to ship it! You'll ask the agent to open a pull request, then review and merge it yourself on github.com. For now we'll manage this manually. In an upcoming lesson we'll explore how Copilot can handle some of the work for you automatically. |
| 97 | + |
| 98 | +1. In the upper right hand corner, select **Create PR**. |
| 99 | +2. If prompted, select **Sign in with your browser** and follow the prompts to authenticate. |
| 100 | +3. Copilot gets to work on creating the PR. |
| 101 | + |
| 102 | +Once the PR is created, Copilot will monitor any workflows on the repository that need to run. After a few moments, the button in the upper right will change to **Ready to merge**. This will be your indication your PR is ready to merge! |
| 103 | + |
| 104 | +4. Select **Ready to merge**. |
| 105 | +5. Select **Merge pull request** on the new dialog window the merge your pull request! |
| 106 | + |
| 107 | +You've now pushed a new feature to the website! |
| 108 | + |
| 109 | +## Summary and next steps |
| 110 | + |
| 111 | +You've started your first agent session and shipped your first change! Specifically, you: |
| 112 | + |
| 113 | +- started an agent session and learned how sessions are structured. |
| 114 | +- directed the agent to make a small, focused change to the game cards. |
| 115 | +- reviewed the change in the workspace diff view. |
| 116 | +- ran the app locally to confirm the star rating in the browser. |
| 117 | +- opened a pull request and merged it yourself on github.com. |
| 118 | + |
| 119 | +Next, you'll use the app to add a custom instructions standard to the repository — starting from one of the issues in your backlog. Continue to [Lesson 3 - Guiding Copilot with custom instructions][next-lesson]. |
| 120 | + |
| 121 | +## Resources |
| 122 | + |
| 123 | +- [Working with agent sessions in the GitHub Copilot app][agent-sessions] |
| 124 | +- [About the GitHub Copilot app][about-copilot-app] |
| 125 | +- [Managing issues and pull requests with the GitHub Copilot app][managing-issues-prs] |
| 126 | + |
| 127 | +[prior-lesson]: 1-install-copilot-app.md#install-and-configure-the-github-copilot-app |
| 128 | +[next-lesson]: 3-custom-instructions.md |
| 129 | +[agent-sessions]: https://docs.github.com/copilot/how-tos/github-copilot-app/agent-sessions |
| 130 | +[about-copilot-app]: https://docs.github.com/copilot/concepts/agents/github-copilot-app |
| 131 | +[managing-issues-prs]: https://docs.github.com/copilot/how-tos/github-copilot-app/managing-issues-and-pull-requests |
0 commit comments