Skip to main content

Lab 4: Agent Mode Deep Dive

๐ŸŽฏ Learning Objectives
  • Implement a complete feature (pagination) using Agent Mode's autonomous loop
  • Observe and understand the Plan โ†’ Code โ†’ Test โ†’ Iterate cycle
  • Understand MCP (Model Context Protocol) and how it extends Copilot's capabilities
  • Experience Copilot cloud agent via GitHub Issues (if org allows)

The Agentic Loop

๐Ÿ“‹ Plan โ†’ ๐Ÿ’ป Code โ†’ ๐Ÿงช Test โ†’ ๐Ÿ”„ Iterate โ†’ โœ… Done

Agent Mode repeats this cycle automatically. It reads errors, adjusts code, re-runs tests, and iterates until the task is complete or it asks for help.

Prerequisites

  • The lab3-api/ project from Lab 3 (or any Express + TypeScript API project)
  • VS Code with Copilot extension โ€” Agent Mode enabled
  • Terminal access for running commands

Exercises

Step 1

Create a GitHub Issue

Start with a well-written issue that describes the feature you want to build. This mirrors real-world development.

Instructions

  1. If you have a GitHub repo for your lab3-api project, create an issue on GitHub.com:
    Title: Add pagination to GET /tasks endpoint
    
    

    Description
    #

    The GET /tasks endpoint currently returns all tasks. For production use,
    we need cursor-based pagination.

    Requirements
    #

    • Add query parameters: limit (default 20, max 100) and cursor (opaque string)
    • Response should include: data (array of tasks), nextCursor (string | null), hasMore (boolean)
    • Tasks should be sorted by createdAt descending (newest first)
    • Invalid limit values should return 400 with descriptive error
    • Cursor should be base64-encoded task ID for simplicity

    Acceptance Criteria
    #

    • GET /tasks returns paginated response

    • GET /tasks?limit=5 returns 5 tasks

    • GET /tasks?cursor=xxx returns next page

    • Invalid parameters return 400

    • Existing tests still pass

    • New tests cover pagination

  2. If you don't have a GitHub repo, copy this issue description to use in the next step โ€” you'll paste it directly into Agent Mode.
๐Ÿ’ก Key Concept: Well-written issues with clear acceptance criteria make Agent Mode (and Copilot cloud agent) dramatically more effective. Vague issues get vague results โ€” just like vague prompts.
Step 2

Implement Pagination with Agent Mode

Hand the feature implementation to Agent Mode and observe the agentic loop in action.

Instructions

  1. Open your lab3-api project in VS Code.
  2. Open Copilot Chat and switch to Agent Mode.
  3. Leave the model picker on "Auto" for this exercise. As of May 20, 2026, Auto in VS Code is task-aware โ€” it will route this multi-step agent task (planning + tool orchestration + bug diagnosis on test failures) to a model suited to it. Hover the response after the run finishes to see which model Auto actually picked.
  4. Paste the issue description (or reference it):
    Implement the pagination feature for GET /tasks as described below:
    

    Requirements:

    • Add query parameters: limit (default 20, max 100) and cursor (opaque string)
    • Response: { data: Task[], nextCursor: string | null, hasMore: boolean }
    • Sort by createdAt descending (newest first)
    • Invalid limit โ†’ 400 error
    • Cursor is base64-encoded task ID
    • Update existing tests and add new pagination tests

    Use the existing codebase in lab3-api/. Don’t break existing endpoints.



  5. Observe the agentic loop carefully. Take notes on each phase:

    • ๐Ÿ“‹ Plan: Does Agent Mode describe what it intends to do before coding? What files does it plan to modify?

    • ๐Ÿ’ป Code: Watch which files it creates or modifies. Does it update types, routes, tests?

    • ๐Ÿงช Test: Does it try to compile or run tests? If something fails, watch what happens next.

    • ๐Ÿ”„ Iterate: If there are errors, does it read them and attempt fixes? How many iterations does it take?



  6. When Agent Mode asks permission to run terminal commands (like npm test), allow it.

  7. When it finishes, review the changes:

What to Verify

  1. Check the response type โ€” does it include data, nextCursor, and hasMore?
  2. Test manually (start the server, then use curl or a REST client):
    # Get first page with limit of 3
    curl http://localhost:3000/tasks?limit=3
    
    

    Use the nextCursor from the response to get the next page
    #

    curl “http://localhost:3000/tasks?limit=3&cursor=CURSOR_VALUE_HERE”

    Test invalid limit
    #

    curl http://localhost:3000/tasks?limit=0
    curl http://localhost:3000/tasks?limit=500



  3. Run the tests:

    cd lab3-api && npx jest --verbose
    </li>
    
โš ๏ธ Important Observation: Agent Mode is powerful but not infallible. You may need to:
  • Clarify requirements if it misunderstands something
  • Reject a change and ask it to try a different approach
  • Fix edge cases it missed (this is normal and expected)
The developer is always the reviewer and decision-maker.
Step 3

Observe the Agent Loop Journal

Document what Agent Mode did to build your understanding of the agentic workflow.

Instructions

Create a brief journal of the loop you observed. Answer these questions:

  1. Planning: How many files did Agent Mode plan to modify? Did it explain its plan before starting?
  2. File changes: List every file Agent Mode created or modified.
  3. Terminal commands: What commands did it run? (npm install? npm test? tsc?)
  4. Iterations: Did it encounter any errors? How many fix-and-retry cycles did it go through?
  5. Quality: Rate the final code quality on a 1โ€“5 scale. What would you change?
๐Ÿ’ก Exam Insight: The exam may describe an agentic workflow scenario and ask you to identify which phase (plan, code, test, iterate) is being described. Understanding this loop is essential.
Step 4

Copilot Cloud Agent via GitHub Issues

Copilot cloud agent (formerly Coding Agent) can be assigned to GitHub Issues to autonomously implement features on a branch.

Instructions

  1. If your organization has Copilot cloud agent enabled:
    • Go to your GitHub Issue from Step 1
    • Assign the issue to Copilot (it appears as an assignable entity)
    • Copilot cloud agent will create a branch, implement the feature, and open a draft PR
    • Review the PR โ€” check the code, run the tests, provide feedback
  2. If your organization does NOT have Copilot cloud agent enabled:
    • You've already done the equivalent using Agent Mode in VS Code (Step 2)
    • The key difference: Copilot cloud agent works asynchronously on GitHub.com โ€” it runs in the cloud, creates its own branch, and opens a PR. Agent Mode works synchronously in your IDE.
๐Ÿ’ก Exam Tip: Key differences to remember:
  • Agent Mode (VS Code): Synchronous, runs locally in your IDE, you watch it work in real time
  • Copilot cloud agent (GitHub.com): Asynchronous, runs in the cloud, assigned via Issues, creates PRs automatically
  • Both follow the same Plan โ†’ Code โ†’ Test โ†’ Iterate loop
Step 5

Understanding MCP (Model Context Protocol)

MCP is an open protocol that lets AI models interact with external tools and data sources. It's how Copilot can be extended beyond its built-in capabilities.

Instructions

  1. In Copilot Chat (any mode), ask:
    What MCP servers are currently configured in my VS Code? List them.
  2. If none are configured, create a basic MCP configuration. Create the file .vscode/mcp.json:
    {
      "servers": {
        "filesystem": {
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
        }
      }
    }
  3. Understand the MCP architecture:
    • MCP Client: The AI application (Copilot) that needs external capabilities
    • MCP Server: A service that provides tools/data via the MCP protocol
    • Protocol: JSON-RPC 2.0 over stdio or HTTP
    • Key concept: MCP is an open standard โ€” not proprietary to GitHub
  4. In Chat, ask about MCP:
    Explain the difference between MCP servers, custom agents, and agent 
    skills. When would you use each?
๐Ÿ’ก Exam Tip: MCP is an open protocol for connecting Copilot to external tools and data. Copilot extensibility rests on MCP servers, custom agents defined in .github/agents/NAME.md, agent skills, and third-party coding agents.
Step 6

Bonus: Agent Mode Error Recovery

Test Agent Mode's ability to recover from intentional failures.

Instructions

  1. Give Agent Mode a task that will initially fail:
    Add a rate limiting middleware to the API that limits each IP address 
    to 100 requests per minute. Use a sliding window algorithm. Store 
    counts in-memory with automatic cleanup of expired entries.
    

    Also add these response headers:

    • X-RateLimit-Limit: 100
    • X-RateLimit-Remaining: (calculated)
    • X-RateLimit-Reset: (Unix timestamp)

    Return 429 Too Many Requests with a Retry-After header when exceeded.



  2. Watch carefully for errors:

    • TypeScript compilation errors โ†’ Does it read the error and fix types?

    • Test failures โ†’ Does it update tests to account for new middleware?

    • Runtime errors โ†’ Does it adjust the implementation?



  3. Count the iterations. A typical complex feature takes 2โ€“4 iterations to get right.

โœ… Completion Checklist

  • Created a well-structured GitHub Issue with acceptance criteria
  • Implemented pagination using Agent Mode
  • Observed and documented the Plan โ†’ Code โ†’ Test โ†’ Iterate loop
  • Manually verified the pagination endpoint works correctly
  • Understand the difference between Agent Mode (IDE) and Copilot cloud agent (GitHub.com)
  • Understand MCP architecture (client, server, open protocol)

๐ŸŽฏ Key Takeaways for the Exam

  • Agent Mode follows Plan โ†’ Code โ†’ Test โ†’ Iterate
  • Agent Mode can execute terminal commands (with user approval)
  • Agent Mode is available on all plans, including Free
  • Copilot cloud agent works asynchronously on GitHub.com via Issues โ†’ PRs
  • MCP = Model Context Protocol = open standard for AI-tool integration
  • MCP uses JSON-RPC 2.0 over stdio or HTTP
  • Extensions are Marketplace apps; MCP servers are protocol-level integrations
  • Well-written issues with clear acceptance criteria produce better agent output