🏗️ Kiến trúc hệ thống
Khám phá cách OpenClaw vận hành "under the hood" - từ Gateway trung tâm đến các AI Agents độc lập.
🗺️ Tổng quan (High-Level)
OpenClaw hoạt động theo mô hình Local-First Architecture. Mọi xử lý logic, lưu trữ dữ liệu và thực thi lệnh đều diễn ra trên máy của bạn (hoặc server của bạn), không phụ thuộc vào cloud server của bên thứ 3 (ngoại trừ LLM API).
graph TD
User[👤 User / Client] -->|WebSocket / HTTP| Network[🌐 Channel Network]
subgraph "Local Machine / VPS (Safe Zone)"
direction TB
Network -->|Auth & Router| Gateway[🛡️ Gateway Core]
Gateway -->|Orchestrate| Agent1[🤖 Agent: Main]
Gateway -->|Orchestrate| Agent2[🤖 Agent: DevOps]
Agent1 <-->|Read/Write| FS[📂 File System]
Agent1 <-->|Store| DB[(🧠 Vector DB)]
Gateway -->|Monitor| Logs[📝 System Logs]
end
Agent1 -.->|Inference| Cloud[☁️ Claude API]
classDef safe fill:#e6fffa,stroke:#00b894,color:#000;
classDef cloud fill:#fff0f6,stroke:#e84393,color:#000;
class Gateway,Agent1,Agent2,FS,DB,Logs one;
🧩 Các thành phần cốt lõi
- 🛡️ Gateway (The Kernel)
- 🤖 Agents (Workers)
- 📱 Clients
Bộ não trung tâm
Gateway là một process **Node.js** chạy daemon (ngầm) 24/7. Nó đóng vai trò như hệ điều hành của Bot.
- 🔌 Connectivity: Quản lý WebSocket Server (port 18789).
- 🚦 Routing: Điều phối tin nhắn từ Client đến đúng Agent.
- 💾 Persistence: Tự động lưu trữ chat history vào SQLite/PostgreSQL.
- 🔐 Security: Kiểm soát Permissions và Sandbox rules.
Protocol: WebSocket + HTTP REST
DB: Better-SQLite3 (Default)
Process: Single-threaded Event Loop
Nhân lực kỹ thuật số
Mỗi Agent là một thực thể độc lập với cấu hình riêng:
🧠 Memory Context
Mỗi agent có vector store riêng, không nhớ nhầm context của agent khác.
🛠️ Toolset
Agent "Dev" có tool Terminal, trong khi Agent "Sale" chỉ có tool Email.
📂 Workspace
Mỗi agent hoạt động trong 1 thư mục root (cwd) cụ thể.
Giao diện để con người tương tác với OpenClaw:
- CLI (`openclaw chat`): Cho developer, tương tác trực tiếp qua pipe.
- Web Dashboard: Quản lý admin, xem logs, settings.
- Channel Adapters: Connectors cho Telegram, Discord, Zalo... biến các nền tảng chat này thành Client.
🔄 Data Flow: Một tin nhắn đi đâu?
Hành trình của tin nhắn "Hello OpenClaw" từ lúc bạn gửi đến khi nhận phản hồi:
2. Processing (Xử lý)
3. Cognition (Suy nghĩ)
4. Action & Response (Hành động)
🔒 Security Model: "Pairing"
Tại sao OpenClaw an toàn hơn các giải pháp khác?
sequenceDiagram
participant U as 👤 User
participant G as 🛡️ Gateway
participant S as 🐚 System Shell
U->>G: "Xóa file data.txt"
G->>G: Check Permission
opt Dangerous Command detected
G-->>U: ⚠️ Command: rm data.txt. DUYỆT? (Y/n)
U->>G: Y (Approve)
end
G->>S: Execute rm data.txt
S-->>G: Done
G-->>U: ✅ Đã xóa