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

Lesson 7: Cloud Agent & Copilot CLI — Agent runs everywhere

Local Agent vs Cloud Agent vs Copilot CLI vs Third-party Agent. Cloud Agent: create branches, implement, open PR automatically. Copilot CLI: run agent from terminal, Git worktrees isolation. Hand off between agent types. Session management.

💻 Programming — Lesson 7 Lesson 7: Cloud Agent & Copilot CLI — Agent run everywhere

Vibe Coding with GitHub Copilot: From Basics to Advanced

Part 2: Agent Mode — AI automatically writes code

xdev.asia

1. Overview of Agent Types

GitHub Copilot allows running agents in many different places, depending on the workflow and level of oversight you need:

Agent Type Where to run? Interaction Main use case
Local Agent VS Code, your machine Interactive Code daily, debug, iterate
Copilot CLI Terminal, background Autonomous Parallel tasks, 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)

This is the agent you learned about in Lesson 5. Local Agent runs in VS Code with full access to workspace:

  • ✅ Access all files in the project
  • ✅ Run terminal commands
  • ✅ Use VS Code extensions and MCP servers
  • ✅ Interactive — you review each step
  • ✅ Debug context (breakpoints, test output)

Best for: Interactive development, debugging, when close oversight is needed.

3. Copilot CLI — Agent from Terminal

Copilot CLI allows running agents from command line, operates autonomously in the background.

3.1. Install

# Copilot CLI được tích hợp trong GitHub CLI
gh extension install github/gh-copilot

Hoặc nếu đã có, upgrade

gh extension upgrade github/gh-copilot

3.2. Basic usage

# 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 — Safe Vibe Coding

Git Worktrees allows Agents to work on one copy separately of the codebase, does not affect the branch you are coding on:

main (bạn đang code ở đây)
  └── worktree/copilot-task-1/ (Agent chạy ở đây)
      └── Isolated copy, riêng branch

When the Agent is completed, review the changes and merge if OK.

3.4. Run multiple tasks in parallel

# 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 on GitHub

Cloud Agent (also called Copilot Coding Agent) runs on GitHub Infrastructure, completely 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

Method 1: Assign GitHub Issue

GitHub Issue → Assignees → Assign to "copilot"

Method 2: Mention in Issue/PR comment

@copilot Can you implement the dark mode feature described in this issue?

Method 3: From VS Code — hand off local session

Select session type dropdown → "Cloud" → Agent continues the task on the cloud.

4.3. Configure Cloud Agent

Create files .github/copilot-coding-agent.yml (or configure via 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 to manage multiple agent sessions
  • Copilot usage metrics tracks active coding agent users

5. Third-party Agents

VS Code supports running agents from other providers:

  • Anthropic (Claude): Use Claude as agent, strong in reasoning
  • OpenAI: use GPT models as agent

Select from session type dropdown → "Third party" → select provider.

6. Hand off between Agent Types

One of the best features: you can Transfer tasks from one agent type to another, keeping the context intact:

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!

How to hand off:

  • Local → CLI: From chat, select "Continue in CLI" from the session type dropdown
  • CLI → Cloud: In CLI session, type /delegate
  • Local → Cloud: Select "Cloud" from the session type dropdown

7. Instructions for choosing Agent Type

Scenario Agent Type recommended
Brainstorm, explore ideas Local Agent (Ask)
Plan implementation Local Agent (Plan)
Build feature interactive Local Agent
Debug with editor context Local Agent
Task background does not need oversight Copilot CLI
Try out many proof of concepts Copilot CLI (worktrees)
Create PR for the review team Cloud Agent
Assign GitHub issue for AI Cloud Agent
Use specific AI provider Third-party Agent

8. Best Practices

  • Use worktrees for experimental tasks — does not affect main branch
  • Configure validation tools for Cloud Agent — ensuring PR quality
  • Monitor usage metrics — track costs and efficiency
  • Hand off when appropriate — plan locally, implement in cloud
  • Review Cloud Agent PRs carefully — like code reviews from junior developers

9. Summary

GitHub Copilot agents are diverse ecosystem — you choose the agent type appropriate to each stage of the development workflow. True strength lies in ability Seamless hand off between types.

From Part 3, we will get into the most important skills for Vibe Coding: Prompt Engineering for Code — how to write prompts so that AI can generate high-quality code.