OpenCode.io.vn
Quay lại Blog
31 tháng 1, 2026OpenCode Vietnam8 phút đọc

Agents vs Skills vs Commands - Chọn đúng công cụ trong OpenCode

Phân biệt Agents, Skills, Commands trong OpenCode. Khi nào dùng gì? Hướng dẫn chi tiết với ví dụ thực tế.

#agents#skills#commands#huong-dan#opencode

Agents vs Skills vs Commands - Chọn đúng công cụ mở rộng

OpenCode có 3 cách mở rộng khả năng AI - nhưng dùng cái nào, khi nào? Đây là câu hỏi mà nhiều người mới bắt đầu thường gặp.

Bài viết này sẽ giúp bạn phân biệt rõ ràng Agents, Skills, và Commands - và quan trọng hơn, biết chọn đúng công cụ cho workflow của mình.


Tổng quan nhanh

┌─────────────────────────────────────────────────────────────────────┐
│  AGENTS = "Nhân cách AI khác nhau"                                  │
│  → Thay đổi AI assistant với model/tools/prompt riêng               │
│  → Persist suốt session hoặc task                                   │
│  → Ví dụ: code-reviewer, security-auditor, docs-writer              │
├─────────────────────────────────────────────────────────────────────┤
│  COMMANDS = "Macro/Shortcut cho User"                               │
│  → Prompt template gọi bằng /command-name                           │
│  → Chạy 1 lần, có thể truyền arguments                              │
│  → Ví dụ: /test, /review, /commit                                   │
├─────────────────────────────────────────────────────────────────────┤
│  SKILLS = "Kiến thức chuyên môn cho Agent"                          │
│  → Agent tự load khi cần (on-demand)                                │
│  → Hướng dẫn domain-specific                                        │
│  → Ví dụ: git-release, pr-review, api-design                        │
└─────────────────────────────────────────────────────────────────────┘

Hãy đi sâu vào từng khái niệm.


1. Agents - "Nhân cách AI" khác nhau

Agent là một AI assistant với cấu hình riêng biệt: model, tools, và system prompt.

Nghĩ đơn giản: Agent như một người đồng nghiệp chuyên môn. Bạn có thể có:

  • @reviewer: Chỉ đọc code, không sửa - chuyên tìm bugs và đề xuất improvements
  • @planner: Dùng model rẻ hơn để brainstorm và lên kế hoạch
  • @security: Focus vào security vulnerabilities

Đặc điểm chính:

  • Persist suốt session hoặc task
  • Có thể dùng model khác (Claude Haiku cho tasks đơn giản, Sonnet cho tasks phức tạp)
  • Có thể giới hạn tools (readonly agent không sửa code)
  • Trigger bằng Tab (switch) hoặc @mention

Ví dụ: Code Reviewer Agent

# .opencode/agent/reviewer.md
---
description: Reviews code for best practices
mode: subagent
model: anthropic/claude-sonnet-4-20250514
tools:
  write: false
  edit: false
  bash: false
---

You are a code reviewer. Focus on:
- Security vulnerabilities
- Performance issues
- Code maintainability
- Best practices

Provide feedback without making changes.

Cách dùng:

@reviewer check this function for issues

2. Commands - "Macro/Shortcut" cho bạn

Command là prompt template - bạn gõ /command-name và OpenCode sẽ chạy prompt đó.

Nghĩ đơn giản: Command như macro trong IDE - một shortcut cho hành động lặp lại.

Đặc điểm chính:

  • Chạy 1 lần rồi xong
  • Có thể truyền arguments ($1, $2, $ARGUMENTS)
  • Có thể inject shell output (!`git diff`)
  • Trigger bằng /command-name

Ví dụ: Test Command với arguments

# .opencode/command/test.md
---
description: Run tests for specific file
agent: build
---

Run tests for $1 and analyze any failures:

## Current test output:
!`npm test -- $1 2>&1`

## Git status:
!`git status --short`

Focus on the failing tests and suggest fixes.

Cách dùng:

/test src/utils.ts

Command này sẽ:

  1. Chạy npm test -- src/utils.ts
  2. Lấy git status
  3. Gửi tất cả vào prompt để AI phân tích

3. Skills - "Kiến thức chuyên môn" cho Agent

Skill là hướng dẫn chi tiết mà Agent tự động load khi cần.

Nghĩ đơn giản: Skill như tài liệu nội bộ - Agent tự tìm đọc khi gặp task liên quan.

Đặc điểm chính:

  • Agent tự quyết định khi nào load (không cần user trigger)
  • Chứa domain knowledge và step-by-step instructions
  • Reusable across projects (có thể làm global skill)
  • Không có arguments, không chạy shell trực tiếp

Ví dụ: Git Release Skill

# .opencode/skill/git-release/SKILL.md
---
name: git-release
description: Create consistent releases and changelogs
---

## What I do
- Draft release notes from merged PRs
- Propose a version bump (major/minor/patch)
- Provide copy-pasteable `gh release create` command

## When to use me
Use when preparing a tagged release.

## Steps
1. Check commits since last tag: `git log $(git describe --tags --abbrev=0)..HEAD --oneline`
2. Categorize changes (features, fixes, breaking)
3. Suggest version based on conventional commits
4. Generate changelog format

Cách dùng:

User: "prepare a release"
→ Agent tự động nhận biết và load skill này

Bảng so sánh chi tiết

Đặc điểmAgentsCommandsSkills
Mục đíchTạo AI assistant chuyên biệtPrompt shortcut lặp lạiKiến thức cho agent tự load
Ai trigger?User (Tab/@mention) hoặc AgentUser/commandAgent tự quyết định
PersistSuốt session/taskChỉ 1 lần gọiKhi agent cần
Custom modelKhông
Custom toolsKhôngKhông
Custom prompt
ArgumentsKhông$1, $ARGUMENTSKhông
Shell outputKhông!`cmd`Không
Vị trí file.opencode/agent/.opencode/command/.opencode/skill/<name>/SKILL.md

Mối quan hệ giữa 3 khái niệm

┌─────────────────────────────────────────────────────────────────┐
│                         USER                                     │
│                           │                                      │
│         ┌─────────────────┼─────────────────┐                   │
│         ▼                 ▼                 ▼                   │
│    /command          Tab/Switch        @mention                 │
│         │                 │                 │                   │
│         ▼                 ▼                 ▼                   │
│   ┌─────────┐      ┌───────────┐     ┌───────────┐              │
│   │ COMMAND │      │  PRIMARY  │     │ SUBAGENT  │              │
│   │ (1 lần) │      │   AGENT   │     │ (task)    │              │
│   └────┬────┘      └─────┬─────┘     └───────────┘              │
│        │                 │                                       │
│        │    ┌────────────┴────────────┐                         │
│        │    │                         │                         │
│        │    ▼                         ▼                         │
│        │  Task tool ──────────► Subagent                        │
│        │    │                                                    │
│        │    ▼                                                    │
│        └──► skill() tool ──────► SKILL (on-demand)              │
│                                                                  │
└─────────────────────────────────────────────────────────────────┘

Các cách kết hợp

Command có thể chỉ định Agent:

# .opencode/command/review.md
---
description: Review current changes
agent: reviewer  # ← Dùng agent reviewer để chạy
---
Review the staged changes.

Agent có thể control Skills:

# .opencode/agent/restricted.md
---
permission:
  skill:
    "internal-*": deny
    "*": allow
---

Sơ đồ quyết định nhanh

Bạn cần gì?
    │
    ├── Chạy prompt cố định nhiều lần? ────────► COMMAND
    │
    ├── AI với model/tools khác? ──────────────► AGENT
    │
    ├── Truyền arguments động? ────────────────► COMMAND
    │
    ├── Agent tự biết cách xử lý? ─────────────► SKILL
    │
    ├── Giới hạn quyền edit/bash? ─────────────► AGENT
    │
    ├── Inject shell output? ──────────────────► COMMAND
    │
    └── Chia sẻ kiến thức cho team? ───────────► SKILL

Use cases thực tế

Use case 1: Code Review

OptionCách dùngKhi nào
COMMAND/review src/api.tsReview nhanh 1 file
AGENT@reviewer analyze the entire src/ folderDeep review nhiều files
SKILLAgent tự load khi detect PR review taskTự động, không cần trigger

Use case 2: Release workflow

1. User: "prepare release v2.0"
2. Agent loads SKILL: git-release (tự động)
3. Agent runs commands dựa theo skill instructions
4. User có thể dùng COMMAND: /changelog để format

Use case 3: Testing

1. User: /test (COMMAND với shell output)
2. Nếu complex debugging → @general (SUBAGENT)
3. Agent có thể load SKILL: debugging-guide

Kết luận

  • AGENT: Khi bạn cần AI với "tính cách" khác - model khác, tools khác, behavior khác
  • COMMAND: Khi bạn muốn shortcut cho prompt lặp lại, có thể truyền args và shell output
  • SKILL: Khi bạn muốn Agent tự biết cách xử lý domain-specific tasks

Ba công cụ này bổ sung cho nhau, không thay thế. Một workflow tốt thường kết hợp cả 3:

  • Commands để trigger actions nhanh
  • Agents để handle tasks chuyên biệt
  • Skills để share knowledge trong team

Bắt đầu với cái bạn cần nhất, rồi mở rộng dần!


Tài liệu tham khảo