OpenClaw: A Deep Dive (translated)
**Architecture, File Structure, and Practical Scenarios** ## Introduction: OpenClaw as a Living Organism OpenClaw is not just a program -- it is a distributed system organized like a living organism. If you picture its anatomy: - **Gateway** -- the heart and nervous system that pumps data and coordinates every process - **Agent** -- the brain that thinks and makes decisions - **Tools** -- the hands that carry out actions - **Workspace** -- long-term memory and personal space - **Sessions** -- short-term conversational memory - **Nodes** -- additional limbs (camera, screen, microphone) This document breaks down the internals of each organ down to the file and config level, shows how they interact, and illustrates everything with practical examples. --- ## Part 1: Gateway -- The Heart of the System ### 1.1 What Is Gateway and Why Does It Exist? Gateway is a long-lived daemon process that: - Maintains persistent connections to channels (Telegram, WhatsApp, Discord, Slack) - Routes incoming messages to the correct agents - Stores session state (conversation history) - Exposes an API (HTTP/WebSocket) for UI and external integrations - Runs periodic tasks (cron, heartbeat) - Manages connected nodes (devices) **Human analogy:** Gateway is the cardiovascular system + nervous system. It pumps events (like blood) between channels and agents and transmits signals (like nerve impulses) from sensory organs (channels) to the brain (agent) and back. ### 1.2 Gateway File Structure All Gateway data lives in `~/.openclaw/`: **`~/.openclaw/config.json`** -- the main Gateway config: - Authentication settings (`gateway.auth.token`/`password`) - WebSocket API port (default 18789) - Channel configs (`telegram.token`, `whatsapp.credentials`, etc.) - Security settings for exec (sandbox, approvals) - Browser tool configs (profiles, executable path) **`~/.openclaw/agents/<agentId>/`** -- per-agent data: - `sessions/sessions.json` -- metadata for all sessions (who, when, channel, status)