AgentSkillsCN

copilot-cli-builder

全面指南:为 GitHub Copilot CLI 构建代理、技能与提示词。当您需要创建自定义代理(.agent.md 文件)、技能(SKILL.md 文件),或为 Copilot CLI 编写自定义指令时,可使用此技能。涵盖工具参考、文件结构、最佳实践,以及提示词工程模式。

SKILL.md
--- frontmatter
name: copilot-cli-builder
description: Comprehensive guide for building agents, skills, and prompts for GitHub Copilot CLI. Use this skill when creating custom agents (.agent.md files), skills (SKILL.md files), or custom instructions for Copilot CLI. Covers tool reference, file structure, best practices, and prompt engineering patterns.

Copilot CLI Builder Skill

Build agents, skills, and prompts for GitHub Copilot CLI.

Copilot CLI Overview

GitHub Copilot CLI is a terminal-native AI agent that:

  • Runs locally with full agentic capabilities (build, edit, debug, refactor)
  • Has GitHub MCP server built-in for repository/issue/PR access
  • Requires explicit user approval for file modifications
  • Supports custom agents, skills, and instructions

Customization Types

TypePurposeFile FormatLocation
Custom AgentSpecialized agent with tailored tools/prompts*.agent.md.github/agents/ or ~/.copilot/agents/
SkillReusable knowledge/workflows/scriptsSKILL.md + resources.github/skills/ or ~/.copilot/skills/
Custom InstructionsRepository-wide context*.instructions.md.github/instructions/ or .github/copilot-instructions.md

When to Use Each

Use CaseRecommended
Restrict tools availableCustom Agent
Specialized workflow for specific taskCustom Agent
Reusable domain knowledgeSkill
Scripts/templates to includeSkill
Repository coding standardsCustom Instructions
General project contextCustom Instructions

Creating Custom Agents

Custom agents are markdown files with YAML frontmatter defining specialized Copilot behavior.

Agent File Structure

markdown
---
name: agent-name
description: Required. What the agent does and when to use it.
tools: ["tool1", "tool2"]
infer: true
---

Agent prompt and instructions in markdown body.
Maximum 30,000 characters.

YAML Properties

PropertyRequiredTypeDescription
nameNostringDisplay name (defaults to filename)
descriptionYesstringPurpose and capabilities
toolsNostring[]Allowed tools. Omit for all tools.
inferNobooleanAuto-select based on context (default: true)
targetNostringvscode or github-copilot

Agent Locations

ScopeLocation
Repository.github/agents/
Personal~/.copilot/agents/
Organization/agents/ in .github-private repo

Tool Configuration

All tools (default): Omit tools property or use tools: ["*"]

Specific tools:

yaml
tools: ["read", "edit", "search", "execute"]

Disable all tools:

yaml
tools: []

Tool Reference

See references/tools.md for complete tool documentation.

Core Tool Aliases:

AliasPurpose
executeShell commands (bash/powershell)
readRead file contents
editCreate/modify files
searchFind files/text
webFetch URLs, web search
agentInvoke other agents

MCP Server Tools:

  • github/* - All GitHub tools (issues, PRs, repos)
  • playwright/* - Browser automation

Agent Prompt Guidelines

  1. Define Role Clearly: State expertise and responsibilities
  2. Set Boundaries: What the agent should/shouldn't do
  3. Specify Outputs: Expected formats and quality standards
  4. Include Context: Domain-specific knowledge

Agent Examples

Read-Only Explorer:

markdown
---
name: code-explorer
description: Analyzes codebases without modifications
tools: ["read", "search"]
---

You explore and explain code. Never modify files.
Focus on architecture, patterns, and dependencies.

Implementation Specialist:

markdown
---
name: implementation-planner
description: Creates implementation plans without coding
tools: ["read", "search", "edit"]
---

You create detailed technical plans in markdown.
Never write production code directly.
Focus on specifications, not implementation.

Creating Skills

Skills are packages of knowledge, scripts, and resources that Copilot loads when relevant.

Skill File Structure

code
skill-name/
├── SKILL.md (required)
└── Optional resources:
    ├── scripts/      - Executable code
    ├── references/   - Documentation for context
    └── assets/       - Templates, images, files

SKILL.md Format

markdown
---
name: skill-name
description: What this skill does and when to use it. Include trigger keywords.
license: Optional license info
---

# Skill Title

Instructions and guidance in markdown.
Keep under 5000 words for efficiency.

Skill Locations

ScopeLocation
Repository.github/skills/
Personal~/.copilot/skills/

Skill Design Principles

  1. Concise is Key: Only include what Copilot doesn't already know
  2. Progressive Disclosure: Core info in SKILL.md, details in references
  3. Trigger Description: Description determines when skill activates

Skill Resource Types

DirectoryPurposeExample
scripts/Executable code for repeatable tasksrotate_pdf.py
references/Documentation loaded on demandapi_docs.md
assets/Files used in output (not loaded)template.html

Skill Example

markdown
---
name: api-testing
description: Patterns for testing REST APIs. Use when writing API tests, mocking HTTP responses, or validating API contracts.
---

# API Testing

## Quick Start

Use `requests` for synchronous tests:
```python
response = requests.get(url)
assert response.status_code == 200

Patterns

For detailed patterns, see:

code

---

## Creating Custom Instructions

Custom instructions provide repository-wide context.

### Instruction File Format

```markdown
---
applyTo: "**/*.ts"  # Optional: glob pattern
---

Instructions for Copilot when working in this repository.

Instruction Locations

FileScope
.github/copilot-instructions.mdEntire repository
.github/instructions/*.instructions.mdPath-specific
AGENTS.mdRepository root
~/.copilot/copilot-instructions.mdAll projects (personal)

Instruction Content Guidelines

  • Repository architecture overview
  • Coding standards and conventions
  • Technology stack details
  • Testing requirements
  • Common patterns to follow

Prompt Engineering Best Practices

Structure Patterns

Role + Task + Constraints:

markdown
You are a [role] specializing in [domain].
Your task is to [specific objective].
Constraints:
- Never [prohibited action]
- Always [required behavior]
- Output format: [expected structure]

Context + Examples + Format:

markdown
## Context
[Background information]

## Examples
Input: X → Output: Y

## Expected Format
[Template or structure]

Quality Patterns

PatternPurpose
Explicit boundariesPrevent scope creep
Output templatesConsistent results
Error handlingGraceful failures
Step-by-stepComplex workflows

Anti-Patterns to Avoid

  • Vague descriptions ("help with code")
  • Contradictory instructions
  • Excessive length (>30K chars for agents)
  • Duplicating Copilot's built-in knowledge

Complete Tool Reference

For detailed tool documentation including parameters and examples, see references/tools.md.

Tool Categories

CategoryToolsPurpose
File Systemread, edit, searchFile operations
ExecutionexecuteShell commands
Webweb_fetch, web_searchInternet access
GitHubgithub/*Repository, issues, PRs
Agentsagent, taskSub-agent delegation

Commonly Used Tools

File Operations:

  • view - Read file contents with line numbers
  • create - Create new files
  • edit - Modify existing files (string replacement)
  • glob - Find files by pattern
  • grep - Search file contents (ripgrep-based)

Execution:

  • powershell - Run shell commands (works on all platforms)
  • Supports sync/async modes
  • Can run Python, Node.js, Go via shell

GitHub MCP Tools:

  • github-mcp-server-list_issues - List issues
  • github-mcp-server-list_pull_requests - List PRs
  • github-mcp-server-search_code - Search code
  • github-mcp-server-get_file_contents - Get remote files
  • github-mcp-server-get_job_logs - Get CI/CD logs

CLI Slash Commands Reference

CommandPurpose
/agentSelect custom agent
/skillsManage skills
/modelSelect AI model
/planEnter plan mode
/reviewCode review agent
/contextShow token usage
/compactSummarize history
/diffReview changes

Decision Framework

Agent vs Skill vs Instructions

code
Need to restrict available tools?
  → Custom Agent

Need reusable scripts/templates?
  → Skill

Need to teach domain-specific workflow?
  → Skill (with references/)

Need repo-wide coding standards?
  → Custom Instructions

Need path-specific rules?
  → Path Instructions (.github/instructions/)

Tool Selection for Agents

code
Agent only analyzes code?
  → tools: ["read", "search"]

Agent creates files?
  → tools: ["read", "edit", "search"]

Agent runs tests/builds?
  → tools: ["read", "execute"]

Agent needs full capability?
  → Omit tools property

Validation Checklist

Before Deploying Agent

  • Description clearly states purpose and triggers
  • Tools list matches actual needs (restrictive is safer)
  • Prompt under 30,000 characters
  • Tested with representative prompts
  • File in correct location for scope

Before Deploying Skill

  • SKILL.md has required frontmatter (name, description)
  • Description includes trigger keywords
  • Instructions under 5000 words
  • Scripts tested and working
  • References organized with clear navigation