TROISINH
Triển khai thực tếKiến trúc nâng cao

GoClaw vs OpenClaw Internals: Kiến trúc bên trong khác gì?

Phân tích kiến trúc nội bộ GoClaw và OpenClaw: tại sao một bên là CLI ephemeral, một bên là middleware message-oriented? Hiểu rõ trade-off giữa cold-start và...

Tại sao hai framework được xây dựng cho cùng một mục đích—tự động hóa coding với AI—lại có kiến trúc nội bộ đối lập đến vậy? GoClaw (Claude Code) và OpenClaw không chỉ khác nhau ở giao diện người dùng; chúng đại diện cho hai triết lý kiến trúc hoàn toàn khác biệt: một là tiến trình tạm thời (ephemeral), một là hệ điều hành lâu dài (persistent).

Vấn đề

Khi bạn chạy agent AI để refactor một codebase lớn, điều gì xảy ra giữa các lần gõ lệnh? Với CLI truyền thống như Claude Code (GoClaw), câu trả lời là: tất cả chết đi. Context window bị xóa, trạng thái tool reset, lịch sử hội thoại biến mất. Bạn phải trả "context establishment tax"—chi phí tái thiết lập ngữ cảnh—mỗi khi khởi động lại.

Điều này tạo ra ba hạn chế nghiêm trọng trong production:

  1. Cold-start latency: 3 đến 5 giây overhead để load SOUL.md, khởi tạo MCP connections, rehydrate vector memory.
  2. Context drift: Con người nhớ "hôm qua ta đã refactor module nào", nhưng agent không, trừ khi bạn manually paste summary vào prompt.
  3. Reactive-only: Agent chỉ phản ứng khi bạn gõ lệnh (pull-based), không thể tự động theo dõi hệ thống vào lúc 3h sáng (push-based).

Cách tiếp cận monolithic "one-shot" này giống như thuê consultant mỗi ngày phải kể lại toàn bộ lịch sử công ty từ đầu.

Ý tưởng cốt lõi

OpenClaw không phải là wrapper quanh LLM—nó là một hệ điều hành (OS), và LLM chỉ là CPU kernel module. Sự khác biệt cốt lõi nằm ở kiến trúc message-oriented middleware (MOM) so với ephemeral CLI process.

Microkernel Architecture

OpenClaw triển khai kiến trúc microkernel:

  • Control Plane (microkernel): Xử lý message routing, access control, session isolation. Nhỏ, trusted, persistent.
  • User-Space Processes (agents): Mỗi chat thread spawn một process cô lập với memory workspace riêng (vector DB + SQLite). Nếu "coding agent" hallucinate và crash, các agent khác không bị ảnh hưởng.

Điều này khác biệt hoàn toàn với GoClaw (Claude Code), nơi agent chạy như một serverless function—khởi động, thực thi, rồi terminate.

Context Assembly Pipeline

Trước khi LLM invocation, OpenClaw thực hiện Context Assembly—tái sử dụng ngữ cảnh từ nhiều nguồn:

  1. Vector memory search: Embeddings từ cuộc trò chuyện trước.
  2. Recent thread history: SQLite-backed state management.
  3. Tool schemas: MCP server capabilities được cache sẵn.
  4. Session-compacted state: State compaction strategies ngăn context window bloat.

Kết quả: Agent "thức dậy" với đầy đủ trí nhớ, không cần "re-introduce" bản thân.

Persistent vs Ephemeral Execution

Đặc điểmGoClaw (Claude Code)OpenClaw
Vòng đờiEphemeral (spawn → run → exit)Persistent (daemon process)
ContextLinear conversation historyHierarchical memory (vector + SQL)
TriggerPull-based (user must type)Push-based (webhook, cron, file change)
Shell authorityAmbient (whatever user has)Sandboxed (Docker + allowlist)
Multi-agentSequential, same contextParallel, isolated workspaces

State Compaction

Vấn đề của persistent agent là unbounded context growth. OpenClaw giải quyết bằng session state compaction—tương tự garbage collection trong OS—nén lịch sử cũ thành summary embeddings, chỉ giữ lại "working set" trong active context window.

Tại sao nó hoạt động

Trade-off: Cold-start vs Baseline Cost

GoClaw tối ưu cho zero-baseline cost: khi không chạy, không tiêu tốn token hay GPU. Nhưng giá phải trả là cold-start latency—mỗi lần invoke phải tái thiết lập toàn bộ toolchain.

OpenClaw đảo ngược trade-off này: warm-start liên tục với chi phí baseline (token duy trì context, SQLite connections, heartbeat monitoring). Điều này giống như so sánh serverless (Lambda) với Kubernetes pod—cái sau tốn tiền "để máy chạy" nhưng phản hồi ngay lập tức.

Ví dụ cụ thể: Khi bạn yêu cầu "tiếp tục refactor từ hôm qua":

  • GoClaw: 3 đến 5 giây để parse SOUL.md, load skills, re-read file tree.
  • OpenClaw: Dưới 100ms—agent đã "sống" trong container, chỉ cần read từ shared memory.

Goroutine vs Event Loop

Tại sao OpenClaw chọn Go (goroutine) thay vì Node.js (event loop) cho agent runtime?

Concurrency model:

  • Node.js: Single-threaded event loop với async/await. Khi agent gọi LLM API (blocking I/O), event loop bị chiếm dụng. Để chạy 1000 agents concurrent, cần 1000 Node processes hoặc complex worker thread pooling.
  • Go: Goroutines (lightweight threads) với M:N scheduling. Một process GoClaw host có thể chạy 10.000+ agents concurrent, mỗi agent là một goroutine riêng biệt với channel-based communication.

Điều này quan trọng cho multi-tenant architecture—mỗi khách hàng một agent instance, nhưng tất cả chạy trong cùng một binary với cô lập bằng RLS (Row-Level Security) và session contexts.

Security Boundary: Shell vs Sandbox

GoClaw chạy với ambient shell authority—quyền của user chạy CLI. Điều này tạo "confused deputy" risk: nếu agent bị inject prompt, nó có quyền xóa production database.

OpenClaw sử dụng Docker sandbox với allowlist policies—mỗi tool execution chạy trong container riêng, network egress bị chặn, filesystem chỉ mount read-only ngoại trừ specific workspace volumes. Đây là capability-based security—agent có quyền chỉ trong phạm vi được cấp, không phải "tài khoản root" của host.

Ý nghĩa thực tế

Production Deployment Patterns

Khi nào chọn GoClaw:

  • Developer cá nhân, làm việc trên laptop, cần tương tác ad-hoc.
  • Tasks ngắn hạn, không cần memory liên tục giữa các session.
  • Yêu cầu security cao với ambient authority (truy cập local dev environment).

Khi nào chọn OpenClaw:

  • Multi-agent teams (secretary, coder, reviewer) chạy 24/7 trên VPS/Mac Mini.
  • Integration với messaging platforms (Telegram, Slack, Zalo OA) cần push-based notification.
  • Enterprise cần audit trail và isolation giữa các department agents.

Benchmarks & Cost Analysis

  • Cold-start: GoClaw từ 3 đến 5 giây vs OpenClaw dưới 100ms cho cached sessions.
  • Baseline cost: OpenClaw tiêu tốn khoảng 20 đến 50 USD/tháng cho persistent VPS (để daemon chạy) vs GoClaw zero cost khi idle.
  • Concurrency: OpenClaw trên 4-core VPS xử lý 500+ concurrent agent sessions nhờ goroutine pool; GoClaw cần orchestration layer (như tmux hoặc systemd) để chạy parallel.

Hạn chế thực tế

OpenClaw không phải silver bullet:

  1. Setup friction: Yêu cầu Docker, security configuration, infrastructure management—không phù hợp cho "vibe coding" ngẫu hứng.
  2. Token consumption: Persistent context maintenance tốn token liên tục (heartbeat, state compaction) dù agent không active.
  3. Security surface: Self-hosted nature tạo attack surface nếu misconfigured (exposed webhooks, weak sandbox escape).
  4. State drift: Dù có compaction, long-running agents vẫn accumulate "epistemic drift"—mô hình thế giới của agent diverge khỏi reality sau hàng tuần chạy liên tục.

Đào sâu hơn

Tài liệu chính thức:

Cùng cụm (Advanced Architecture):

Đọc tiếp:

Mở rộng:

On this page