Agent Mode & Implementation

How to set up and use Copilot's AI agents for real coding work — from inline completions to autonomous multi-file changes.

Back

⚙️ Setting Up Your Project

copilot-instructions.md

This is your project's AI constitution. Create .github/copilot-instructions.md to set coding standards, architecture constraints, and naming conventions. Applied to every Copilot suggestion.

# Architecture - Use repository pattern. Never call DbContext directly from controllers. - All new services must implement an interface and be registered in DI. # Coding Standards - C# 12, .NET 8. Use file-scoped namespaces. - Async methods must have Async suffix. - No magic strings — use constants or configuration. # Constraints - Never modify the migration history. - All public API endpoints require [Authorize] attribute.

Custom Skills (SKILL.md)

Encode repeatable patterns as reusable agent knowledge. A skill is a SKILL.md file plus optional scripts.

Location Purpose
.github/skills/extract-service/SKILL.md Step-by-step service extraction pattern
.github/skills/add-endpoint/SKILL.md API endpoint scaffolding with tests
.github/skills/migrate-db/SKILL.md Safe database migration workflow

MCP Servers

Connect Copilot to external data. Configure in .vscode/mcp.json.

Connection What It Provides
PostgreSQL / SQL Server Query schemas and data directly in context
Jira / Azure DevOps Pull ticket details and requirements
Confluence / Wiki Access documentation and architecture decisions
Custom internal APIs Domain-specific data and operations

🚀 Using Agent Mode

Agent Mode vs Coding Agent

Feature Agent Mode (VS Code) Coding Agent (GitHub.com)
Where VS Code, local GitHub.com, cloud
Trigger Chat panel, Ctrl+I Assign issue to @copilot
Scope Multi-file, runs terminal Full repo, creates branch + PR
Supervision You watch in real-time Asynchronous, review the PR
Best for Complex tasks you want to steer Well-defined issues, autonomous work

Effective Agent Mode Prompts

1. Refactoring:

Extract the add-to-cart logic from ShoppingCartController into a CartService. Update all callers and add unit tests. Don't change existing behaviour.

2. Feature implementation:

Add Redis caching to the ProductService.GetById method. Use IDistributedCache. Cache for 5 minutes. Include cache invalidation when product is updated.

3. Multi-file scaffolding:

Create a new NotificationService following the repository pattern in this project. Include: interface, implementation, DI registration, unit tests. Follow the same structure as OrderService.

The Feedback Loop

Agent mode's real power is its feedback loop. It runs terminal commands (build, test, lint), reads the output, and self-corrects. Make sure your project has: a working build command, runnable tests, and a linter. The better your harness, the better the agent performs.

📚 Resources

🔗
Build Applications with Copilot Agent Mode
Learn agent fundamentals and advanced patterns
🔗
Customize Your Copilot Experience
Configure instructions and adapt to your workflow
🔗
Integrate MCP with Copilot
Connect external data sources and tools
🔗
Expand Your Team with Copilot
Scale your team's capabilities with AI