1. Tổng quan Agent Types
GitHub Copilot cho phép chạy agents ở nhiều nơi khác nhau, tùy theo workflow và mức độ oversight bạn cần:
| Agent Type | Chạy ở đâu | Tương tác | Use case chính |
|---|---|---|---|
| Local Agent | VS Code, máy của bạn | Interactive | Code hàng ngày, debug, iterate |
| Copilot CLI | Terminal, background | Autonomous | Tasks song song, worktree isolation |
| Cloud Agent | GitHub cloud | Via PR | Team collaboration, issue → PR |
| Third-party | Anthropic/OpenAI | SDK-based | Specific AI provider preference |
2. Local Agent (VS Code)
Đây là agent bạn đã học ở Bài 5. Local Agent chạy trong VS Code với full access vào workspace:
- ✅ Truy cập tất cả files trong project
- ✅ Chạy terminal commands
- ✅ Sử dụng VS Code extensions và MCP servers
- ✅ Interactive — bạn review mỗi step
- ✅ Debug context (breakpoints, test output)
Best for: Interactive development, debugging, khi cần oversight chặt.
3. Copilot CLI — Agent từ Terminal
Copilot CLI cho phép chạy agent từ command line, hoạt động autonomous trong background.
3.1. Cài đặt
# Copilot CLI được tích hợp trong GitHub CLI gh extension install github/gh-copilotHoặc nếu đã có, upgrade
gh extension upgrade github/gh-copilot
3.2. Sử dụng cơ bản
# Chạy agent task gh copilot agent "Add input validation to all API endpoints in src/routes/"Với worktree isolation (không ảnh hưởng branch hiện tại)
gh copilot agent --worktree "Refactor database queries to use prepared statements"
3.3. Git Worktrees — An toàn khi Vibe Coding
Git Worktrees cho phép Agent làm việc trên một copy riêng của codebase, không ảnh hưởng branch bạn đang code:
main (bạn đang code ở đây)
└── worktree/copilot-task-1/ (Agent chạy ở đây)
└── Isolated copy, riêng branch
Khi Agent hoàn thành, bạn review changes và merge nếu OK.
3.4. Chạy song song nhiều tasks
# Terminal 1: Task A gh copilot agent --worktree "Add unit tests for UserService"Terminal 2: Task B (song song)
gh copilot agent --worktree "Create API documentation with OpenAPI spec"
Terminal 3: Bạn vẫn code bình thường trên main branch
4. Cloud Agent — Coding Agent trên GitHub
Cloud Agent (còn gọi Copilot Coding Agent) chạy trên GitHub infrastructure, hoàn toàn autonomous:
4.1. Workflow
┌─────────────────────────────────────────────────┐
│ CLOUD AGENT WORKFLOW │
├─────────────────────────────────────────────────┤
│ │
│ 1. Assign issue/task cho Agent │
│ (assign to "copilot" on GitHub) │
│ ↓ │
│ 2. Agent tự tạo branch │
│ ↓ │
│ 3. Agent implement changes │
│ (code, tests, docs) │
│ ↓ │
│ 4. Agent mở Pull Request │
│ ↓ │
│ 5. Team review PR như bình thường │
│ ↓ │
│ 6. Merge khi approved │
│ │
└─────────────────────────────────────────────────┘
4.2. Trigger Cloud Agent
Cách 1: Assign GitHub Issue
GitHub Issue → Assignees → Assign to "copilot"
Cách 2: Mention trong Issue/PR comment
@copilot Can you implement the dark mode feature described in this issue?
Cách 3: Từ VS Code — hand off local session
Chọn session type dropdown → "Cloud" → Agent tiếp tục task trên cloud.
4.3. Configure Cloud Agent
Tạo file .github/copilot-coding-agent.yml (hoặc cấu hình qua repo settings):
# Validation tools cho Cloud Agent
validation:
- name: "lint"
command: "npm run lint"
- name: "test"
command: "npm test"
- name: "build"
command: "npm run build"
4.4. Monitoring Cloud Agent
- Trace commits → session logs (Mar 2026 feature)
- Session filters để quản lý multiple agent sessions
- Copilot usage metrics tracks active coding agent users
5. Third-party Agents
VS Code hỗ trợ chạy agents từ các provider khác:
- Anthropic (Claude): dùng Claude as agent, mạnh về reasoning
- OpenAI: dùng GPT models as agent
Chọn từ session type dropdown → "Third-party" → chọn provider.
6. Hand off giữa Agent Types
Một trong những tính năng hay nhất: bạn có thể chuyển task từ agent type này sang type khác, giữ nguyên context:
Ví dụ workflow end-to-end:
1. LOCAL (Plan): Lập kế hoạch feature mới
↓ hand off
2. LOCAL (Agent): Implement interactive, review từng step
↓ hand off
3. COPILOT CLI: Chạy parallel tasks cho testing
↓ hand off
4. CLOUD (Agent): Tạo PR, team review
Context được chuyển toàn bộ qua mỗi hand off!
Cách hand off:
- Local → CLI: Từ chat, chọn "Continue in CLI" từ session type dropdown
- CLI → Cloud: Trong CLI session, gõ
/delegate - Local → Cloud: Chọn "Cloud" từ session type dropdown
7. Hướng dẫn chọn Agent Type
| Scenario | Agent Type khuyên dùng |
|---|---|
| Brainstorm, explore ý tưởng | Local Agent (Ask) |
| Lập kế hoạch implementation | Local Agent (Plan) |
| Build feature interactive | Local Agent |
| Debug với editor context | Local Agent |
| Task background không cần oversight | Copilot CLI |
| Thử nhiều proof of concepts | Copilot CLI (worktrees) |
| Tạo PR cho team review | Cloud Agent |
| Assign GitHub issue cho AI | Cloud Agent |
| Dùng specific AI provider | Third-party Agent |
8. Best Practices
- Dùng worktrees cho experimental tasks — không ảnh hưởng main branch
- Cấu hình validation tools cho Cloud Agent — đảm bảo PR quality
- Monitor usage metrics — theo dõi chi phí và efficiency
- Hand off khi phù hợp — plan locally, implement in cloud
- Review Cloud Agent PRs cẩn thận — như review code từ junior developer
9. Tổng kết
GitHub Copilot agents là hệ sinh thái đa dạng — bạn chọn agent type phù hợp với từng giai đoạn của development workflow. Sức mạnh thực sự nằm ở khả năng hand off liền mạch giữa các types.
Từ Phần 3, chúng ta sẽ đi vào kỹ năng quan trọng nhất cho Vibe Coding: Prompt Engineering cho Code — cách viết prompt để AI sinh ra code chất lượng cao.