Creating Custom Agents
Custom agents are specialized GitHub Copilot agents with tailored expertise, tools, and instructions for specific tasks. This guide shows you how to create effective custom agents using real examples from the community.What are Custom Agents?
Custom agents are markdown files with YAML frontmatter that define:- Agent identity and expertise - What the agent specializes in
- Available tools - Which operations the agent can perform
- Instructions - How the agent should work and respond
- Model selection - Which AI model powers the agent
Custom agents live in
.github/agents/ (repository-level) or agents/ (organization/enterprise-level).Anatomy of a Custom Agent
Here’s the basic structure:Quick Start: Your First Agent
Let’s create a simple code review agent:Test the agent
- Reload VS Code or refresh GitHub.com
- Select “Code Reviewer” from the Copilot Chat dropdown
- Ask it to review a file or code snippet
Real-World Example: PR Comment Addresser
Here’s a production agent from the Awesome Copilot repository:Frontmatter Properties
Required Properties
Brief, single-quoted description of the agent’s purpose (50-150 characters)
Optional Properties
Display name for the agent in the UI (defaults to filename if omitted)
List of tools the agent can use. If omitted, agent has access to all tools.
AI model to use (strongly recommended)
Whether Copilot can automatically use this agent based on context
Tool Configuration
Standard Tool Aliases
All tool names are case-insensitive:- File Operations
- Execution
- Web & External
- Agents
read- Read file contentsedit- Edit and modify filessearch- Search for files or text in files (Grep, Glob)
Tool Selection Examples
Agent Instructions
The markdown content below the frontmatter defines agent behavior:Structure Template
Best Practices
Be Specific and Direct
Be Specific and Direct
Use imperative mood (“Analyze”, “Generate”) and avoid vague terms.Good: “Analyze code for security vulnerabilities using OWASP Top 10”Avoid: “Help with security”
Define Clear Boundaries
Define Clear Boundaries
Explicitly state what the agent should and shouldn’t do.
Include Examples
Include Examples
Show the agent what good output looks like.
Keep It Focused
Keep It Focused
One agent should do one thing well. Create multiple agents rather than one that does everything.
Common Agent Patterns
Testing Specialist
Tools: All tools for comprehensive test creationFocus: Analyze code, identify gaps, write tests, avoid production changes
Code Reviewer
Tools:
read, search onlyFocus: Analyze and suggest improvements, no direct modificationsRefactoring Specialist
Tools:
read, search, editFocus: Improve code structure while maintaining behaviorSecurity Auditor
Tools:
read, search, webFocus: Identify vulnerabilities, check against OWASP, report findingsAdvanced: Agent Handoffs
Create guided sequential workflows that transition between agents:Handoffs are currently supported in VS Code 1.106+ only.
File Organization
Repository-Level Agents
Organization-Level Agents
Testing Your Agent
Manual Testing
- Create the agent file with proper frontmatter
- Reload VS Code or refresh GitHub.com
- Select the agent from Copilot Chat dropdown
- Test with representative queries
- Verify tool access works as expected
Refinement
Based on agent responses:
- Adjust instructions for clarity
- Add or remove tools as needed
- Refine output format expectations
Common Mistakes to Avoid
Example Agents from the Community
Explore real production agents:- Address Comments - Automatically address PR review comments
- Accessibility Expert - WCAG compliance and a11y best practices
- Test Specialist - Comprehensive test coverage analysis
- Security Reviewer - Security vulnerability detection