Chuyển đến nội dung chính

レッスン 12: カスタム エージェントとエージェント スキル — 特化した AI の作成

カスタム エージェント (.agent.md) を作成します: ロール、ツール、手順。 YAML のフロントマター。エージェント スキル (SKILL.md): 再利用可能なドメインの知識。例: コード レビューアー エージェント、ドキュメント ライター エージェント、テスト ジェネレーター エージェント。 .github/agents/ を介してチーム内でエージェントを共有します。

💻 プログラミング — レッスン 12 レッスン 12: カスタム エージェントとエージェント スキル — 作成 Specialized AI

GitHub Copilot を使用した Vibe コーディング: 基本から高度まで

パート 4: コパイロットのカスタマイズと拡張

xdev.asia

1.カスタムエージェントとは何ですか?

カスタム エージェントを使用すると、 Specialized AI personas 特定のタスク用。 Each agent has:

  • 役割: 特定の役割 (レビュー担当者、テスター、文書作成者)
  • ツール: 使用が許可されているツールのリスト
  • 指示: detailed instructions for behavior
  • モデル: 特定のモデルを指定できます (オプション)

2. Create Custom Agent

2.1.ファイル構造

Custom agents are files .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. Realistic Custom Agents example

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

  1. Security: Check for injection, auth flaws, secrets exposure
  2. Performance: N+1 queries, unnecessary re-renders, memory leaks
  3. Error handling: Missing try-catch, unhandled promises
  4. Type safety: Any usage of any, missing types
  5. Testing: Coverage gaps, missing edge cases
  6. Naming: Clear, consistent naming following conventions
  7. 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 Agent

You 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 describe blocks for grouping, it for 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:

  1. Read the source code thoroughly
  2. Identify all code paths and branches
  3. Check existing tests for patterns
  4. Write tests, run them, fix any failures

3.3. Architect Agent

<!-- .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:

  1. List at least 2-3 alternative approaches
  2. Compare with pros/cons table
  3. Consider: scalability, maintainability, cost, team expertise
  4. Recommend with clear reasoning
  5. 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)

エージェントスキルは domain knowledge modules can be reused by multiple agents.各スキルはファイルです スキル.md。

4.1. Create Skills

<!-- .github/skills/database-migration/SKILL.md -->
---
name: 'Database Migration'
description: 'Best practices cho Prisma database migrations'
---
# Database Migration Skill

Migration Checklist

  1. Always create migration with descriptive name
  2. Test migration on staging data before production
  3. Include rollback strategy for every migration
  4. Never modify existing migrations after push
  5. Use prisma migrate diff to review changes

Common Patterns

  • Adding nullable column: safe, no downtime
  • Renaming column: 3-step migration (add new → copy data → drop old)
  • Adding index: use CREATE INDEX CONCURRENTLY for large tables

Commands

# 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. Reference Skill in Agent

<!-- 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.カスタムエージェントを使用する

  1. チャットビューを開く (Ctrl+Cmd+I)
  2. Click agent dropdown (default "Agent")
  3. 作成したカスタム エージェント (Reviewer、TestWriter など) を選択します。
  4. 通常どおりプロンプトを表示します - エージェントは役割と指示に従います

6. Configure Tools for Agents

List of assignable tools:

ツール 機能 リスクレベル
読む ファイルの読み取り Low (read-only)
編集ファイル ファイルを編集する 平均
runInターミナル コマンドを実行する 高
検索します。検索 コードベースの検索 低い
web ウェブを検索する 低い
エージェント。エージェント サブエージェントに委任する 平均
vscode/askQuestions ユーザーに質問する 低い

セキュリティに関するヒント: Review-only agents (Reviewer) should いいえ 編集ファイル そして runInターミナル。

7. チーム内でエージェントを共有する

Commit all .github/agents/ リポジトリに移動 → すべてのメンバーに同じエージェントが割り当てられます。これは、チームの AI ワークフローを標準化する方法です。

8. まとめ

コンセプト ファイル 目的
カスタムエージェント .agent.md AI ペルソナと役割 + ツール + 指示
エージェントスキル スキル.md Domain knowledge module, reusable
プロンプトファイル .prompt.md 再利用可能なプロンプトテンプレート
指示 .instructions.md ファイルタイプ固有のルール

次の曲はカバーになります MCPサーバー — Copilot を Figma、データベース、API、および外部ツールに接続します。