๐Ÿ—๏ธ Architecture

How OpenClaw works under the hood. From message to response.

System Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                         YOUR PHONE                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚  โ”‚ Telegram โ”‚  โ”‚ WhatsApp โ”‚  โ”‚ Discord  โ”‚  โ”‚ Matrix   โ”‚        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚             โ”‚             โ”‚             โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                             โ”‚
                             โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                     GATEWAY (your machine)                       โ”‚
โ”‚                     ws://127.0.0.1:18789                         โ”‚
โ”‚                                                                  โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”‚
โ”‚  โ”‚  Channels   โ”‚  โ”‚  Sessions   โ”‚  โ”‚   Cron      โ”‚              โ”‚
โ”‚  โ”‚  Manager    โ”‚  โ”‚  Manager    โ”‚  โ”‚  Scheduler  โ”‚              โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ”‚
โ”‚         โ”‚                โ”‚                โ”‚                      โ”‚
โ”‚         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ”‚
โ”‚                          โ”‚                                       โ”‚
โ”‚                          โ–ผ                                       โ”‚
โ”‚                  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                               โ”‚
โ”‚                  โ”‚ Agent Runtime โ”‚โ—„โ”€โ”€โ”€โ”€ Workspace Files          โ”‚
โ”‚                  โ”‚ + Tool Router โ”‚      (SOUL.md, etc.)          โ”‚
โ”‚                  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                           โ”‚
                           โ–ผ
                   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                   โ”‚  AI Provider  โ”‚
                   โ”‚  (Claude, GPT, โ”‚
                   โ”‚   OpenAI...)  โ”‚
                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Core Components

๐ŸŒ

Gateway

The central process that runs on your machine. It:

  • Manages all channel connections
  • Routes messages to the right session
  • Handles the WebSocket control plane
  • Runs cron jobs and heartbeats
  • Serves the web UI on port 18789
openclaw gateway status
๐Ÿ’ฌ

Sessions

Each conversation is a session with its own context:

  • Main session: Your primary DM chat
  • Isolated sessions: Groups, cron jobs
  • Sub-agents: Spawned for background work

Sessions maintain conversation history and can share the workspace.

๐Ÿค–

Agent Runtime

The runtime that processes requests, model calls, tools, memory, and sub-agent orchestration. It:

  • Reads your workspace files for context
  • Has access to tools (file ops, exec, web)
  • Streams responses back to channels
  • Runs in RPC mode for tool calling
๐Ÿ“

Workspace

Your agent's home directory (~/.openclaw/workspace/):

  • SOUL.md โ€” Core personality
  • USER.md โ€” Info about you
  • MEMORY.md โ€” Long-term context
  • memory/ โ€” Daily logs
  • brain/ โ€” Second brain docs

Message Flow

What happens when you send a message:

1

Message Received

You send "Check my calendar" via Telegram

2

Gateway Routes

Gateway identifies your session and loads context

3

Context Built

Workspace files (SOUL.md, etc.) are loaded as system prompt

4

Agent Processes

The agent runtime calls the AI provider with your message + context

5

Tools Execute

Agent uses tools (gog skill) to check your Google Calendar

6

Response Streams

Response streams back to Telegram as the agent types

Key Concepts

๐Ÿ” Loopback-First

Gateway WebSocket defaults to localhost only. Use Tailscale or SSH tunnels for remote access. Security by default.

๐Ÿ“ก One Gateway Per Host

Use account IDs/profiles for channel isolation where supported. For browser-backed channels such as WhatsApp Web, keep ownership clear so two gateways do not fight over the same paired session.

๐Ÿง  Context Injection

Workspace files are injected as system prompt context. The agent reads them every turn to maintain personality and memory.

๐Ÿ”„ Session Isolation

DMs share a main session. Groups get isolated sessions. Cron jobs run in isolated sessions to avoid context pollution.

๐Ÿ› ๏ธ Tool Streaming

Tools execute as the agent works. File reads, web fetches, and commands stream results back to the conversation.

๐Ÿ“ฆ Skills = Instructions

Skills are just markdown files with instructions. They tell the agent how to use external tools โ€” no code required.

Network Topology

๐Ÿ  Local Mode (Default)

Gateway binds to 127.0.0.1:18789. Only accessible from the same machine. Most secure.

๐ŸŒ Tailscale Mode

Gateway binds to Tailscale interface. Accessible from your Tailnet. Requires token auth.

openclaw gateway --bind tailnet --token xxx

๐Ÿ”— Remote via SSH

SSH tunnel to forward the local port. Works with any server.

ssh -L 18789:localhost:18789 user@server