AI Agent cho Developer: Từ assistant đến đồng đội thực sự — hoatq.dev

cat blog/.md

AI Agent cho Developer: Từ assistant đến đồng đội thực sự

date: tags: ai, automation, developer-tools, productivity

AI coding assistant không còn là “gợi ý autocomplete” nữa. Năm 2026, chúng ta có AI Agent — những trợ lý có khả năng đọc code, chạy lệnh, kết nối API, và thực thi cả một workflow phức tạp. Nhưng vấn đề là: phần lớn developer chỉ dùng 10% khả năng của chúng.

Bài viết này mình chia sẻ cách mình thiết lập AI agent (cụ thể là Claude Code) để nó trở thành “đồng đội” thực sự — không chỉ viết code, mà còn hiểu project, tuân thủ convention, và tự động hóa các task lặp đi lặp lại.

Agent là gì? Khác gì chatbot?

Chatbot: Bạn hỏi → nó trả lời. Một chiều, không ngữ cảnh, không hành động.

Agent: Bạn giao task → nó lập kế hoạch, đọc file, chạy lệnh, sửa code, test, rồi báo cáo kết quả. Nó có khả năng sử dụng tools và tự quyết định bước tiếp theo.

Chatbot:  "Hãy viết unit test cho hàm này" → trả về đoạn code
Agent:    "Hãy viết unit test cho hàm này" → đọc source → phân tích deps
          → tạo test file → chạy pytest → fix lỗi → commit

Sự khác biệt nằm ở tool use — agent có thể gọi tools (đọc file, chạy terminal, tìm kiếm code, gọi API) để hoàn thành task một cách tự chủ.

Sub-Agent: Chia để trị

Khi task phức tạp, một agent đơn lẻ sẽ bị quá tải context. Giải pháp: sub-agent — agent con được sinh ra để xử lý một phần cụ thể của task, rồi báo kết quả về agent chính.

Main Agent: "Refactor module authentication"
  ├── Sub-agent 1: Tìm tất cả file liên quan đến auth
  ├── Sub-agent 2: Phân tích test coverage hiện tại
  └── Sub-agent 3: Kiểm tra breaking changes với API consumers

Ưu điểm:

  • Song song hóa: Nhiều sub-agent chạy cùng lúc, nhanh hơn rất nhiều
  • Cô lập context: Mỗi sub-agent chỉ load phần cần thiết, không bị nhiễu
  • An toàn hơn: Sub-agent có thể chạy trong sandbox (worktree riêng), không ảnh hưởng code chính

Mình hay dùng pattern này khi cần research codebase lớn — thay vì để agent chính đọc 50 file, mình spawn một sub-agent chuyên explore rồi trả về summary.

Skills: Dạy agent “cách làm việc” của team bạn

Đây là feature mình thấy game-changer nhất. Skill là một file markdown định nghĩa behavior cho agent — giống như onboarding document cho team member mới, nhưng agent đọc và tuân thủ 100% thời gian.

Cấu trúc một Skill

skills/
├── coding/
│   └── SKILL.md          # Backend coding standards
├── frontend-coding/
│   └── SKILL.md          # Frontend conventions
└── ui-ux-pro-max/
    ├── SKILL.md           # Design system intelligence
    ├── scripts/           # CLI tools cho agent gọi
    └── data/              # CSV databases (styles, colors, fonts...)

Ví dụ: Backend Coding Skill

---
name: "Backend Coding Standards"
description: "Enforce KISS, DRY, SRP, YAGNI principles"
globs:
  - "**/*.py"
---

# Backend Coding Standards

## Layer Rules
- **Router**: HTTP adapter only. NO business logic.
- **Service**: Business logic. NO SQL queries.
- **Repository**: Data access only. NO business rules.

## Mandatory
- ALWAYS use type hints
- ALWAYS use early return pattern
- NEVER mix layer responsibilities

Khi agent mở file .py, skill này tự động kích hoạt nhờ globs. Agent sẽ tuân thủ layered architecture, dùng type hints, viết early return — mà không cần bạn nhắc lại mỗi lần.

Skill nâng cao: CLI tools + data

Skill không chỉ là text. Bạn có thể đính kèm scripts để agent gọi trực tiếp. Ví dụ, mình có skill UI/UX chứa database 50+ design styles, 97 color palettes, 57 font pairings:

# Agent tự gọi script này khi cần chọn design system
python3 skills/ui-ux-pro-max/scripts/search.py \
  "beauty spa elegant" --design-system -p "Serenity Spa"

Agent không cần “nhớ” 97 palettes trong context — nó query khi cần, giống developer tra docs vậy.

MCP: Model Context Protocol — kết nối agent với thế giới bên ngoài

MCP cho phép agent gọi tools từ external services — GitHub, Jira, database, VPS, Figma, Google Sheets… bất kỳ thứ gì có API.

Cách hoạt động

Agent ←→ MCP Server ←→ External Service
          (bridge)

MCP server là một process trung gian, expose các tools cho agent sử dụng. Ví dụ, một MCP server cho GitHub sẽ cung cấp tools: create_issue, list_pull_requests, get_file_contents

Ví dụ thực tế: Agent deploy lên VPS

Mình có một MCP source kết nối tới VPS qua SSH. Agent có thể:

# Agent đọc guide trước khi dùng
Read: /sources/vps-hoatq/guide.md

# Rồi thực hiện deploy
ssh -p 2018 root@server "ls /data/www/"    # Kiểm tra thư mục
rsync -avz dist/ root@server:/data/www/     # Deploy static files
ssh -p 2018 root@server "nginx -t"          # Test nginx config

Toàn bộ flow: build → deploy → verify, agent xử lý hết chỉ với một câu lệnh “Deploy lên VPS”.

Tự tạo MCP source

Mỗi source gồm 2 file chính:

sources/my-service/
├── config.json    # Connection settings, auth
└── guide.md       # Hướng dẫn sử dụng cho agent

guide.md đặc biệt quan trọng — đây là nơi bạn “dạy” agent cách dùng service: rules nào cần tuân thủ, endpoint nào available, workflow nào nên follow.

Hooks: Tự động hóa trước và sau mỗi hành động

Hooks cho phép bạn chạy script tự động khi agent thực hiện một action cụ thể. Giống git hooks, nhưng cho AI agent.

Ví dụ: Auto-lint sau khi agent sửa code

{
  "hooks": {
    "afterEdit": {
      "command": "eslint --fix ${file}",
      "description": "Auto-fix lint issues after edit"
    },
    "beforeCommit": {
      "command": "npm run test -- --related",
      "description": "Run related tests before commit"
    }
  }
}

Hooks đảm bảo quality gate luôn được enforce — agent sửa code xong, linter tự chạy, test tự chạy, không cần bạn nhắc.

Use cases phổ biến

HookMục đích
afterEditFormat code, lint, type check
beforeCommitChạy test, check coverage
afterFileCreateThêm license header, boilerplate
onErrorLog lỗi, notify Slack

Thiết lập một luồng automation hoàn chỉnh

Giờ hãy kết hợp tất cả lại. Đây là workflow thực tế mình dùng hàng ngày:

1. Context files — Agent hiểu project từ đầu

project/
├── CLAUDE.md              # Project overview, architecture, conventions
├── backend/
│   └── CLAUDE.md          # Backend-specific: models, routes, patterns
├── frontend/
│   └── CLAUDE.md          # Frontend-specific: pages, composables
└── shared/
    └── CLAUDE.md          # Shared packages, cross-service patterns

CLAUDE.md là “sổ tay dự án” cho agent. Mỗi khi agent bắt đầu session mới, nó đọc file này để hiểu architecture, conventions, và tech stack — không cần giải thích lại.

2. Skills — Enforce coding standards tự động

skills/
├── coding/SKILL.md           # Python: KISS, DRY, SRP, type hints
├── frontend-coding/SKILL.md  # TypeScript: component patterns, hooks
└── ui-ux-pro-max/SKILL.md    # Design: colors, fonts, accessibility

3. MCP Sources — Kết nối external services

sources/
├── github/        # Tạo PR, review code, manage issues
├── vps-hoatq/     # Deploy, server management
├── figma/         # Đọc design tokens, component specs
└── jira/          # Sync tasks, update status

4. Memory — Agent nhớ qua các session

Agent có thể lưu “memory” — thông tin persist qua các conversation:

# memory/feedback_testing.md
---
name: feedback_testing
type: feedback
---
Integration tests phải dùng real database, không mock.
**Why:** Team từng bị incident vì mock test pass nhưng prod migration fail.

Lần sau agent viết test, nó tự nhớ: “À, project này không dùng mock DB” — mà không cần bạn nhắc lại.

5. Flow hoàn chỉnh

Developer: "Implement feature login with OAuth2"

    ├── Agent đọc CLAUDE.md → hiểu architecture
    ├── Skill [coding] activate → enforce conventions
    ├── Sub-agent: Research OAuth2 best practices
    ├── Agent code backend (service → repo → router)
    ├── Hook afterEdit → auto lint + type check
    ├── Agent viết tests (real DB, không mock)
    ├── Hook beforeCommit → chạy test suite
    ├── MCP [github] → tạo PR với description
    └── Memory → lưu lại decisions cho session sau

Tips từ kinh nghiệm thực tế

1. Context file quan trọng hơn bạn nghĩ

Đầu tư 30 phút viết CLAUDE.md chi tiết sẽ tiết kiệm hàng giờ giải thích cho agent. Ghi rõ: tech stack, folder structure, naming conventions, common patterns.

2. Skill nên specific, không generic

# ❌ Quá chung chung
"Viết code clean và tốt"

# ✅ Specific và actionable
"Router layer: NO try/except, NO HTTPException.
 Service layer owns error handling.
 Repository: use repository_util helpers."

3. Đừng cho agent quá nhiều quyền ngay từ đầu

Bắt đầu với permission mode “Ask to Edit” — agent phải hỏi trước khi sửa file. Khi đã tin tưởng workflow, mới chuyển sang “Execute” cho các task routine.

4. Review output, đừng blind trust

Agent rất giỏi nhưng không hoàn hảo. Luôn review code changes trước khi commit, đặc biệt với:

  • Logic nghiệp vụ phức tạp
  • Security-sensitive code
  • Database migrations
  • Infrastructure changes

5. Feedback loop là chìa khóa

Khi agent làm sai, nói cho nó biết tại sao. Agent có memory — lần sau nó sẽ tránh lặp lại lỗi tương tự. Đây là cách “train” agent theo cách làm việc của team bạn.


AI agent không thay thế developer — nó khuếch đại năng lực của bạn. Một developer biết tận dụng agent, skills, hooks và MCP đúng cách có thể làm việc hiệu quả gấp nhiều lần — không phải vì code nhanh hơn, mà vì giảm cognitive loadtự động hóa những thứ lặp đi lặp lại.

Bắt đầu nhỏ: viết một CLAUDE.md, tạo một skill cho coding convention, kết nối một MCP source. Rồi bạn sẽ thấy sự khác biệt.

// reactions



hoatq@dev : ~/blog $