Skip to main content

OpenClaw

An open-source, self-hosted autonomous AI agent that operates through messaging platforms you already use — WhatsApp, Telegram, Slack, Discord, Signal, iMessage, and more. Model-agnostic, built in TypeScript, with a hub-and-spoke architecture separating a Gateway control plane from sandboxed agent runtimes. Created by Peter Steinberger.


Architecture


Hub-and-Spoke Design

OpenClaw splits into two primary components:

Gateway — a Node.js WebSocket server (127.0.0.1:18789, loopback-only) that acts as the single control plane. Connects to all messaging platforms via channel adapters, manages session state and access control, and routes messages to the agent runtime. Exactly one Gateway runs per host.

Agent Runtime — executes AI interactions in a four-phase pattern per turn:

PhaseFunction
Session ResolutionMaps messages to sessions — DMs get full capabilities, group chats are sandboxed
Context AssemblyLoads session history from JSON, builds system prompts from workspace files (AGENTS.md, SOUL.md, TOOLS.md), runs semantic memory search
Model + Tool ExecutionStreams to the configured model, intercepts tool calls, executes tools (in Docker sandbox for untrusted sessions), feeds results back
State PersistencePersists session state to disk as append-only event logs with branching support

The core agent loop itself is handled by the Pi agent framework — OpenClaw's value is in everything around the loop: channel normalization, session management, memory, security, and sandboxing.


Channel Adapter Pattern

Each messaging platform has a dedicated adapter implementing a common interface:

ResponsibilityWhat It Does
AuthenticationQR codes (WhatsApp), tokens (Telegram/Discord), OAuth (Slack)
Inbound ParsingNormalizes messages, attachments, and reply context into a common format
Access ControlAllowlists, DM pairing codes, group mention requirements
Outbound FormattingConverts markdown, respects platform message limits, uploads media

Adding a new channel means writing one adapter without touching any agent logic. Supported platforms include WhatsApp, Telegram, Slack, Discord, Signal, iMessage, Microsoft Teams, Google Chat, and Matrix.


Model Provider System

OpenClaw is model-agnostic with support for 14+ providers using a provider/model reference format (e.g., anthropic/claude-opus-4-6):

CategoryProviders
CloudAnthropic, OpenAI, Google Gemini, Mistral, xAI, Groq, Cerebras
RoutingOpenRouter, GitHub Copilot, Hugging Face Inference
LocalOllama, vLLM, LM Studio — any OpenAI-compatible endpoint

Custom providers are configured via models.providers in openclaw.json. Authentication uses environment variables or OAuth flows.


Tool System

Tools are organized into groups with a cascading permission resolution chain where deny always wins:

GroupTools
Filesystemread, write, edit, apply_patch
Runtimeexec, bash, process
Memorymemory_search, memory_get
Sessionssessions_list, sessions_history, sessions_send, sessions_spawn
Webweb_search, web_fetch
UIbrowser, canvas
Othercron, gateway, nodes, image, message

Permission Resolution Chain

Permissions cascade through six layers, each only able to narrow access:

  1. Tool profile base allowlist (minimal, coding, messaging, full)
  2. Global allow/deny rules
  3. Provider-specific policies
  4. Agent-level overrides
  5. Group/session-specific restrictions
  6. Sandbox tool policies

Execution Contexts

Tools can execute in three contexts:

  • sandbox — Docker container (ephemeral, isolated filesystem)
  • gateway — the Gateway host machine
  • node — a paired remote device (macOS/iOS/Android)

Skills System

Skills are reusable playbooks — pure documentation, not executable code — that teach the agent how to combine tools for specific tasks.

A skill is a directory containing a SKILL.md file with YAML frontmatter (name, description, dependencies, required binaries) and markdown instructions. Skills are loaded from workspace, agent, and bundled directories.

The key design principle: tools provide capabilities, skills provide knowledge. Installing the Obsidian skill teaches OpenClaw how to organize notes, but without the write tool enabled, it cannot write files. This separation is deliberate.

Skills are snapshotted at session start. Only relevant skills for the current turn are injected into the system prompt to avoid prompt bloat.


Memory Architecture

Memory is built on plain Markdown files stored on disk as the authoritative source. Nothing persists in RAM alone.

FilePurposeLoaded When
memory/YYYY-MM-DD.mdDaily logs, append-only running contextToday's and yesterday's at session start
MEMORY.mdLong-term durable facts, decisions, preferencesPrivate sessions only
SOUL.mdPersonality, tone, values, non-negotiable constraintsAlways
AGENTS.mdCore operational instructionsAlways
TOOLS.mdUser-specific tool conventionsAlways

Semantic Search (Hybrid BM25 + Vector)

Memory retrieval combines two approaches:

  • Vector similarity (70% weight) for semantic matching
  • BM25 keyword matching (30% weight) for exact tokens
  • MMR post-processing reduces redundant results (lambda: 0.7)
  • Temporal decay with 30-day half-life — evergreen files like MEMORY.md skip decay

Indexes stored in SQLite at ~/.openclaw/memory/<agentId>.sqlite, with optional sqlite-vec for accelerated vector queries.

Context Compaction

When a session approaches the context window limit, OpenClaw triggers a silent agentic turn that prompts the model to write durable memories to disk before compaction. The flush uses a NO_REPLY option so users see nothing.


Session-Based Trust

Session identifiers encode trust levels:

PatternTrust LevelAccess
agent:<id>:mainOperatorFull host access
agent:<id>:<channel>:dm:<id>UntrustedDocker-sandboxed
agent:<id>:<channel>:group:<id>UntrustedDocker-sandboxed

Unknown senders must go through a DM pairing code approval flow before messages are processed. Open public access requires explicit opt-in.


Agent-to-Agent Communication

Sessions can communicate via sessions_send, sessions_history, and sessions_spawn — enabling multi-agent coordination without switching chat surfaces. Each session has its own lane with serial execution by default. Parallelism is opt-in.


Patterns Used

PatternHow It's Used
ReActCore agent loop — reason, call tools, observe results, repeat
Tool RouterModel selects from 20+ tools via function calling
RouterChannel adapters normalize messages from any platform into a common format
File-Based MemoryMEMORY.md, SOUL.md, daily logs — all plain Markdown on disk
Vector StoreHybrid BM25 + vector semantic search over memory files
Human-in-the-LoopDM pairing codes, cascading deny-always-wins permission chain
Hierarchical AgentSessions can spawn sub-sessions for delegated tasks
Conversation SummarizationSilent compaction flushes memories to disk before context compression
Code ExecutionDocker sandbox for untrusted session tool execution