Implement a Scoped Feature in Copilot Agent Mode with Repo Discovery and Tests

Guides GitHub Copilot agent mode to inspect the repository, state assumptions, plan a minimal change, implement it, and add tests. It ends with a verification report you can use to decide whether to open a PR.

You get: Working code with an explanation

More like this

The prompt

implement-a-scoped-feature-in-copilot-agent-mode-with-repo-discovery-and-tests.md
Role: You are a senior {language_and_framework} engineer working in GitHub Copilot agent mode inside my open workspace. You follow existing repository conventions and prefer the smallest correct change.

Context: I need to ship a scoped change. The decision I must make at the end is whether this change is ready for a pull request or needs more work. Use #codebase and any .github/copilot-instructions.md file to learn conventions before editing.

Task: Implement {feature_description}, add or update tests, and report verification results honestly.

Inputs
- Feature description: {feature_description}
- Likely files or folders: {target_paths}
- Language and framework: {language_and_framework}
- Test command: {test_command}
- Constraints (compatibility, performance, style): {constraints}
- Acceptance criteria from the ticket: {acceptance_criteria}
- Out of scope: {out_of_scope}
If any input is blank or ambiguous, list it under Missing information and ask at most 3 targeted questions. Proceed only on assumptions that are low risk, and label each one.

Workflow
1. Discovery: search the codebase for related modules, existing patterns, similar features, and current tests. List the files you read and why they matter. Do not edit yet.
2. Assumptions: list assumptions separately from facts found in the repo.
3. Plan: give a numbered plan of file-level changes, each tied to an acceptance criterion. Flag anything that touches public APIs, schemas, config, or dependencies.
4. Implement: make the minimal edits that satisfy the plan. Reuse existing helpers. Do not add new dependencies unless unavoidable, and justify any you add.
5. Test: add or update tests for the happy path, at least two edge cases, and one failure path. Match the existing test style.
6. Verify: run {test_command} in the terminal if available. Report only real output. If you cannot run it, say so and give the exact command for me to run.
7. Self-review: re-read your diff for unrelated changes, dead code, missing error handling, and leaked secrets.

Constraints
- Do not modify files outside {target_paths} without stating why first.
- Do not refactor unrelated code or reformat whole files.
- Do not invent APIs, functions, or config keys; confirm they exist in the repo.
- Never claim tests passed unless you saw them pass.
- Honor: {constraints}

Output format
Return these sections in order:
1. Summary (3 sentences max)
2. Missing information and assumptions (table: item | type fact/assumption/missing | impact)
3. Plan (numbered list)
4. Files changed (table: file | change | acceptance criterion covered)
5. Tests added or updated (table: test name | scenario | expected result)
6. Verification (command, actual result, or not run and why)
7. Risks and follow-ups (bulleted, each with a suggested next action)
8. PR readiness verdict: Ready, Ready with caveats, or Not ready, with one-line justification

Acceptance criteria
- Every item in {acceptance_criteria} maps to at least one code change and one test.
- The diff contains no changes outside the stated scope, or each such change is justified.
- New tests fail without the change and pass with it, or the report explains why that was not checked.
- Verification states real results or clearly says not run.

Quality checks
- Does the code follow naming, error handling, and logging patterns found in neighboring files?
- Are all new public functions typed or documented per repo convention?
- Did you avoid hard-coded secrets, URLs, and environment-specific paths?
- Is each assumption either confirmed in code or listed for me to confirm?
- Is the verdict consistent with the risks listed?

Example output

AI-written example
--- a/app/api/orders.py
+++ b/app/api/orders.py
@@
-from fastapi import APIRouter, Depends
+from fastapi import APIRouter, Depends, Query
 from sqlalchemy.orm import Session
 
 from app.db.session import get_db
-from app.models.order import Order
+from app.models.order import Order, OrderStatus
 from app.schemas.order import OrderRead
@@
 router = APIRouter(prefix="/orders", tags=["orders"])
 
 
 @router.get("", response_model=list[OrderRead])
 def list_orders(
+    status: OrderStatus | None = Query(
+        default=None,
+        description="Return only orders in this status. Omit to return all.",
+    ),
     limit: int = Query(50, ge=1, le=200),
     offset: int = Query(0, ge=0),
     db: Session = Depends(get_db),
 ):
-    return db.query(Order).order_by(Order.created_at.desc()).limit(limit).offset(offset).all()
+    query = db.query(Order)
+    if status is not None:
+        query = query.filter(Order.status == status)
+    return query.order_by(Order.created_at.desc()).limit(limit).offset(offset).all()
# tests/api/test_orders.py  (appended; reuses existing `client` and `make_order` fixtures)

import pytest

from app.models.order import OrderStatus


def test_list_orders_filters_by_status(client, make_order):
    make_order(status=OrderStatus.PENDING)
    make_order(status=
Generated from this prompt by AI. Your results will vary.

Tips and common edits

Use in VS Code Copilot Chat agent mode with the repo open. Fill every variable first; a precise {test_command} and {out_of_scope} greatly reduce drift. Review the plan before letting it edit, and confirm the test results yourself in your terminal or CI.

Questions about this prompt

Coding Agent Task Brief with Guardrails, Test Plan, and Rollback Steps

Creates a scoped brief for an AI coding agent that limits file changes, defines tests, and includes a rollback plan and review checklist.

Conventional Commit and PR Description from a Diff and Ticket

Produces a Conventional Commits message and a reviewer-ready PR description covering what changed, why, how to test it, and the risks, based on your diff and ticket.

Rewrite a Vague Issue into a Copilot Coding Agent-Ready Issue

Turns a vague GitHub issue into a self-contained task with context, testable acceptance criteria, files to touch, and tests to add, so the Copilot coding agent can finish it.

Edge-Case Test Suite for One Function in Your Existing Test Framework

Writes tests for a single function that cover normal inputs, boundaries, bad input and error paths, in the test framework your project already uses.

GitHub Copilot Pull Request Description Written From the Diff

Turns the changes in a branch into a clear pull request description: what changed and why, how to test it, risks and screenshots to add, in your repo's template if it has one.

Pre-PR Self-Review and Pull Request Description from a Git Diff

Has GitHub Copilot review your branch diff against the base branch, flag defects and missing tests, and draft a PR description with evidence. Use it to decide whether to open the PR or fix issues first.

Cursor Characterization-Test-First Refactor of a Legacy Module

Has Cursor lock in current behavior with characterization tests before restructuring a legacy module in small steps, so you can decide whether the refactor preserved behavior and is safe to merge.

Plan Before Edit: Cursor Plan-Mode Prompt for a Feature Request

Produces a read-only Cursor plan listing files in scope, ordered steps, specific risks and tests to run before any code is changed.

Typed Phase Handoff Contracts and Validator for Multi-Agent Pipelines

Has Claude Code define schema-based handoff contracts between agent phases, generate a validator, and add contract tests. Supports the decision of which phase boundaries need strict contracts versus lightweight checks.

Custom GPT Blueprint: Instructions, Knowledge Files, and Test Cases

Plan a custom GPT before building it. Produces the instruction text, knowledge file plan, conversation starters, and a test set so you can decide whether to build, narrow, or skip it.

Pre-Merge Code Review Checklist Skill (SKILL.md)

A save-ready SKILL.md that has your coding agent review a branch before merge: correctness, security, tests and migrations, with findings ranked by severity and no style nitpicks.

Test-First Bug Fix Skill: Reproduce, Fix, Prove (SKILL.md)

A SKILL.md that forces your coding agent to reproduce a bug with a failing test before changing code, apply the smallest fix, and prove it with the test suite.