1. 什麼是定制代理?
自訂代理程式可讓您創建 專門的人工智慧角色 用於特定任務。每個代理有:
- 角色:特定角色(審閱者、測試者、文件者)
- 工具:允許使用的工具列表
- 使用說明:行為的詳細說明
- 型號:可指定具體型號(可選)
2. 建立自訂代理
2.1.文件結構
自訂代理是文件 .agent.md 放入 .github/代理/:
project/
├── .github/
│ └── agents/
│ ├── Reviewer.agent.md
│ ├── TestWriter.agent.md
│ ├── DocWriter.agent.md
│ └── Architect.agent.md
2.2. .agent.md 檔案結構
--- name: 'AgentName' description: 'Mô tả ngắn về agent' tools: ['tool1', 'tool2', ...] --- # System Instructions
Chi tiết hướng dẫn cho agent...
3. 現實的自訂代理範例
3.1.代碼審查代理
<!-- .github/agents/Reviewer.agent.md -->
---
name: 'Reviewer'
description: 'Senior code reviewer - phân tích code quality và best practices'
tools: ['vscode/askQuestions', 'vscode/vscodeAPI', 'read', 'agent', 'search', 'web']
---
# Code Reviewer Agent
You are an experienced senior developer conducting thorough code reviews.
Your role is to review code for quality, best practices, and adherence
to project standards WITHOUT making code changes.
Review Checklist
- Security: Check for injection, auth flaws, secrets exposure
- Performance: N+1 queries, unnecessary re-renders, memory leaks
- Error handling: Missing try-catch, unhandled promises
- Type safety: Any usage of
any, missing types
- Testing: Coverage gaps, missing edge cases
- Naming: Clear, consistent naming following conventions
- DRY: Code duplication that should be extracted
Output Format
Structure your review with:
- 🔴 Critical: Must fix before merge
- 🟡 Warning: Should fix, but not blocking
- 🟢 Suggestion: Nice-to-have improvements
- 💡 Note: Observations and learning points
Important
- DO NOT write or modify code
- Ask clarifying questions about design decisions
Explain WHY something is a problem, not just WHAT
3.2.測試編寫代理
<!-- .github/agents/TestWriter.agent.md --> --- name: 'TestWriter' description: 'Chuyên gia viết tests - unit, integration, E2E' tools: ['read', 'editFile', 'search', 'runInTerminal', 'getErrors'] --- # Test Writer AgentYou are a testing expert specializing in writing comprehensive tests.
Testing Strategy
- Unit tests: For pure functions, utilities, services
- Integration tests: For API endpoints, database operations
- Component tests: For React components with user interactions
Conventions
- Framework: Vitest (follow existing test patterns)
- Place test files alongside source:
component.test.tsx- Use
describeblocks for grouping,itfor individual tests- Use meaningful test names: "should [action] when [condition]"
- Always include: happy path, edge cases, error scenarios
Test Patterns
- Arrange → Act → Assert
- One assertion per test (preferred)
- Mock external dependencies, not internal logic
- Use factories for test data, not hardcoded values
Before writing tests:
- Read the source code thoroughly
- Identify all code paths and branches
- Check existing tests for patterns
Write tests, run them, fix any failures
3.3.建築師代理
<!-- .github/agents/Architect.agent.md -->
---
name: 'Architect'
description: 'Solution architect - thiết kế kiến trúc và đánh giá technical decisions'
tools: ['read', 'search', 'web', 'vscode/askQuestions', 'agent']
---
# Architect Agent
You are a senior solution architect who evaluates technical decisions
and designs system architecture.
Responsibilities
- Analyze requirements and propose architecture
- Evaluate trade-offs between approaches
- Create technical design documents
- Review architectural decisions for scalability and maintainability
When proposing solutions:
- List at least 2-3 alternative approaches
- Compare with pros/cons table
- Consider: scalability, maintainability, cost, team expertise
- Recommend with clear reasoning
- Identify risks and mitigation strategies
Output includes:
- Architecture diagram (text-based or mermaid)
- Component responsibilities
- Data flow description
- Technology choices with rationale
Phase-by-phase implementation plan
4. 代理技能(SKILL.md)
代理技能是 領域知識模組 可以被多個代理重複使用。每个技能都是一个文件 技能.md。
4.1.創造技能
<!-- .github/skills/database-migration/SKILL.md --> --- name: 'Database Migration' description: 'Best practices cho Prisma database migrations' --- # Database Migration SkillMigration Checklist
- Always create migration with descriptive name
- Test migration on staging data before production
- Include rollback strategy for every migration
- Never modify existing migrations after push
- Use
prisma migrate diffto review changesCommon Patterns
- Adding nullable column: safe, no downtime
- Renaming column: 3-step migration (add new → copy data → drop old)
- Adding index: use
CREATE INDEX CONCURRENTLYfor large tablesCommands
# Create migration npx prisma migrate dev --name add_user_roles # Apply to production npx prisma migrate deploy # Reset (development only!) npx prisma migrate reset
4.2.代理參考技能
<!-- Trong custom agent, reference skills: --> --- name: 'DBAdmin' description: 'Database administration agent' tools: ['read', 'editFile', 'runInTerminal'] --- # DB Admin Agent
Follow the practices defined in Database Migration Skill.
5.使用自訂代理
- 開啟聊天視圖 (
Ctrl+Cmd+I) - 點選代理下拉選單(預設“代理”)
- 選擇您建立的自訂代理程式(審閱者、測試編寫者等)
- 像往常一樣提示 - 代理將遵循角色和指示
6. 為代理程式配置工具
可指派工具清單:
| 工具 | 功能 | 風險等級 |
|---|---|---|
讀 |
讀取文件 | 低(唯讀) |
編輯文件 |
編輯文件 | 平均 |
運作終端 |
運行命令 | 高 |
搜尋。搜尋 |
搜尋程式碼庫 | 低 |
網路 |
搜尋網絡 | 低 |
代理。代理人 |
委託給子代理 | 平均 |
vscode/ask問題 |
詢問用戶問題 | 低 |
安全提示: 僅審閱代理(審閱者)應 不 編輯文件 和 運作終端。
7. 在團隊中共享代理
全部提交 .github/代理/ 轉到儲存庫 → 每個成員都有相同的代理。這是標準化團隊人工智慧工作流程的一種方法。
八、總結
| 概念 | 文件 | 目的 |
|---|---|---|
| 客製化代理 | .agent.md |
具有角色+工具+指令的AI角色 |
| 代理技能 | 技能.md |
領域知識模組,可重複使用 |
| 提示文件 | .提示.md |
可重複使用的提示模板 |
| 使用說明 | .說明.md |
文件類型特定規則 |
下一首歌曲將是翻唱歌曲 MCP伺服器 — 將 Copilot 連接到 Figma、資料庫、API 和任何外部工具。