|
| 1 | +# [Custom Agents (.agent.md)](https://code.visualstudio.com/docs/copilot/customization/custom-agents) |
| 2 | + |
| 3 | +Custom personas with specific tools, instructions, and behaviors. |
| 4 | + |
| 5 | +## Locations |
| 6 | + |
| 7 | +| Path | Scope | |
| 8 | +|------|-------| |
| 9 | +| `.github/agents/*.agent.md` | Workspace | |
| 10 | +| `<profile>/agents/*.agent.md` | User profile | |
| 11 | + |
| 12 | +## Frontmatter |
| 13 | + |
| 14 | +```yaml |
| 15 | +--- |
| 16 | +description: "<required>" # For agent picker and subagent discovery |
| 17 | +name: "Agent Name" # Optional, defaults to filename |
| 18 | +tools: ["search", "fetch"] # Optional: built-in, MCP (<server>/*), extension |
| 19 | +model: "Claude Sonnet 4" # Optional, uses picker default |
| 20 | +argument-hint: "Task..." # Optional, input guidance |
| 21 | +infer: true # Optional, enable on-demand subagent discovery (default: true) |
| 22 | +handoffs: [...] # Optional, transitions to other agents |
| 23 | +--- |
| 24 | +``` |
| 25 | + |
| 26 | +## Tools |
| 27 | + |
| 28 | +Specify tool names in the `tools` array. Sources: built-in tools, tool sets, MCP servers (`<server>/*`), or extension-contributed tools. |
| 29 | + |
| 30 | +To discover available tools, search your current tool list or use the tool search capability. |
| 31 | + |
| 32 | +**Special**: `[]` = no tools, omit = defaults. Body reference: `#tool:<name>` |
| 33 | + |
| 34 | +### Tool Aliases |
| 35 | + |
| 36 | +Common aliases for restricting agent capabilities: |
| 37 | + |
| 38 | +| Alias | Purpose | |
| 39 | +|-------|---------| |
| 40 | +| `shell` | Execute shell commands | |
| 41 | +| `read` | Read file contents | |
| 42 | +| `edit` | Edit files (exact tools vary) | |
| 43 | +| `search` | Search files or text | |
| 44 | +| `custom-agent` | Invoke other custom agents as subagents | |
| 45 | +| `web` | Fetch URLs and web search | |
| 46 | +| `todo` | Create and manage task lists | |
| 47 | + |
| 48 | +### Common Restriction Patterns |
| 49 | + |
| 50 | +```yaml |
| 51 | +# Read-only agent (no editing, no execution) |
| 52 | +tools: ["read", "search"] |
| 53 | + |
| 54 | +# MCP-only agent |
| 55 | +tools: ["myserver/*"] |
| 56 | + |
| 57 | +# No terminal access |
| 58 | +tools: ["read", "edit", "search"] |
| 59 | + |
| 60 | +# Planning agent (research only) |
| 61 | +tools: ["search", "web", "read"] |
| 62 | +``` |
| 63 | +
|
| 64 | +For the full list of available tools, see the [VS Code documentation](https://code.visualstudio.com/docs/copilot/customization/custom-agents). |
| 65 | +
|
| 66 | +## Template |
| 67 | +
|
| 68 | +```markdown |
| 69 | +--- |
| 70 | +description: "Generate implementation plans" |
| 71 | +tools: ["search", "fetch", "githubRepo", "usages"] |
| 72 | +--- |
| 73 | +You are in planning mode. Generate plans, don't edit code. Include: Overview, Requirements, Steps, Testing. |
| 74 | +``` |
| 75 | +
|
| 76 | +## Invocation |
| 77 | +
|
| 78 | +- **Manual**: Agents dropdown or `Chat: Switch Agent...` command |
| 79 | +- **On-demand (subagent)**: When `infer: true`, parent agent can delegate based on `description` match—like skills and instructions |
| 80 | + |
| 81 | +## When to Use |
| 82 | + |
| 83 | +**Key Signal**: Orchestrated multi-stage processes with role-based tool restrictions. Different stages need different capabilities or strict handoffs. |
| 84 | + |
| 85 | +## Domain Examples |
| 86 | + |
| 87 | +| Domain | Example Workflow | |
| 88 | +|--------|------------------| |
| 89 | +| Engineering | planner → implementer → reviewer → deployer | |
| 90 | +| Product | research → strategy → execution → measurement | |
| 91 | +| Analytics | scope → build → analyze → report | |
| 92 | +| Support | triage → troubleshoot → escalate → close | |
| 93 | +| Content | research → write → edit → publish | |
| 94 | + |
| 95 | +## Creation Process |
| 96 | + |
| 97 | +### 1. Gather Requirements |
| 98 | + |
| 99 | +- What role or persona should this agent embody? |
| 100 | +- What specific tools does this role need (and which should it NOT have)? |
| 101 | +- Should this be workspace-specific or personal (user profile)? |
| 102 | +- Will this agent hand off to other agents? |
| 103 | + |
| 104 | +### 2. Determine Location |
| 105 | + |
| 106 | +| Scope | Path | |
| 107 | +|-------|------| |
| 108 | +| Workspace | `.github/agents/<name>.agent.md` | |
| 109 | +| User profile | `<profile>/agents/<name>.agent.md` | |
| 110 | + |
| 111 | +### 3. Create the File |
| 112 | + |
| 113 | +```markdown |
| 114 | +--- |
| 115 | +description: "<role description for agent picker>" |
| 116 | +tools: ["<minimal tool set>"] |
| 117 | +--- |
| 118 | +You are a <role>. Your responsibilities: |
| 119 | +- <primary responsibility> |
| 120 | +- <constraints on behavior> |
| 121 | +
|
| 122 | +<Specific instructions for this role> |
| 123 | +``` |
| 124 | + |
| 125 | +### 4. Configure Handoffs (optional) |
| 126 | + |
| 127 | +If this agent is part of a workflow: |
| 128 | +```yaml |
| 129 | +handoffs: |
| 130 | + - agent: "next-stage-agent" |
| 131 | + condition: "When <trigger condition>" |
| 132 | +``` |
| 133 | + |
| 134 | +## Core Principles |
| 135 | + |
| 136 | +1. **Single role per agent**: Each agent embodies one persona with focused responsibilities |
| 137 | +2. **Minimal tool set**: Only include tools required for the role—excess tools dilute focus and increase risk |
| 138 | +3. **Clear boundaries**: Define what the agent should NOT do as clearly as what it should do |
| 139 | +4. **Explicit handoffs**: When workflows span agents, define clear transition triggers |
| 140 | +5. **Discoverable via description**: The `description` field drives agent picker display—make it actionable |
| 141 | +6. **Keyword-rich for subagent discovery**: When `infer: true`, the `description` determines automatic delegation—include trigger words and use cases so the parent agent knows when to invoke this subagent |
| 142 | + |
| 143 | +## Anti-patterns |
| 144 | + |
| 145 | +- **Swiss-army agents**: Agents with many tools that try to do everything |
| 146 | +- **Missing constraints**: Agents without clear boundaries on what they shouldn't attempt |
| 147 | +- **Role confusion**: Description doesn't match the persona defined in the body |
| 148 | +- **Circular handoffs**: Agent A hands to B which hands back to A without progress criteria |
| 149 | +- **Tool sprawl**: Using `tools: []` to disable all tools when specific restrictions would suffice |
| 150 | +- **Vague subagent descriptions**: Generic descriptions like "A helpful agent" that don't help the parent decide when to delegate—use phrases like "use proactively after code changes" for clear triggers |
0 commit comments