MMNTM logo
7-Part Technical Series

OpenClaw

Anatomy of a Personal AI Agent

Most agent frameworks are cloud-first API wrappers: your messages go to a server, get processed, responses come back. OpenClaw inverts the model. It's a local-first personal AI agent platform — a single gateway process that runs on your machine, owns all session state, and connects to messaging platforms, model providers, and tools as interchangeable spokes.

The philosophy is explicit: the “Brain” (LLM) can be rented from any provider, but the “Body” — execution environment, memory, tools, identity — must belong to the user.

7 articles~80 min reading1 CVE
OpenClaw architecture visualization
Layer 1

The Gateway

The gateway is the control plane. A single TypeScript process owns all session state, transcripts, and lifecycle management. Messaging platforms (WhatsApp, Telegram, Matrix, Discord, Slack — 29+ protocols), model providers (Anthropic, OpenAI, Google, Ollama), and tool servers all connect to this hub. Nothing routes around it.

FeatureOpenClaw (Local-First)Cloud Agent (Typical)
Data ownershipUser owns all state under ~/.openclaw/Vendor owns conversation data
Model lock-inSwap providers via config changeTightly coupled to one provider
Channel support29+ protocols as pluginsUsually 1–2 (web, API)
LatencyLocal processing + API callNetwork round-trip for everything
Offline capabilityMemory/tools work offline, LLM needs networkFully dependent on network

Two architectural decisions stand out. First, lane-based concurrency: each conversation gets its own execution lane with an independent queue, so a slow tool call in one chat doesn't block another. Second, execution approval gating: the gateway can require human confirmation before running shell commands, providing a kill switch between the model's intent and the system's actions.

Protocols are plugins. Adding a new messaging platform means implementing a ChannelPlugin interface — the gateway doesn't privilege any platform over another. WhatsApp, Matrix, and Nostr are all first-class citizens.

Layer 2

The Intelligence Layer

The gateway moves messages. The intelligence layer decides what to do with them. OpenClaw treats the system prompt as compiled output, not static configuration. At session start, a prompt compiler assembles the system prompt from runtime context: available tools, channel capabilities, identity files, installed skills, and conversation history.

The same agent on the same machine produces different system prompts depending on which tools are available, which channel the message arrived on, and what files exist in the workspace. The prompt is an emergent property of the runtime environment.

Context management follows a prune-then-inject pattern. OpenClaw tracks token budgets per session, compresses older messages via summarization, and reserves space for tool results. Session keys identify conversations uniquely, allowing the agent to maintain separate context windows for different chats even when they share the same underlying model.

Skills discovery is dynamic: the gateway scans for installed skills at startup and injects their tool definitions into the system prompt. Add a skill, restart the gateway, and the agent gains new capabilities without any code changes.

Layer 3

Memory

Without persistence, an AI agent suffers digital anterograde amnesia — it meets you for the first time at the start of every session. OpenClaw's memory architecture solves this with a hybrid approach.

BM25 (Keyword)

Exact matches, names, IDs, technical terms

TF-IDF term frequency scoring

Vector (Semantic)

Conceptual similarity, paraphrased queries

Embedding cosine similarity

Hybrid (OpenClaw)

Production use — both exact and fuzzy

Parallel BM25 + vector, reciprocal rank fusion

The design principle is files as canonical source of truth. MEMORY.md holds curated long-term facts. Daily log files (memory/YYYY-MM-DD.md) are append-only. The vector index and BM25 index are derived from these files — they can be rebuilt at any time. When something breaks, debugging is reading, not querying.

The pre-compaction flush: Before OpenClaw compacts a conversation to free context space, it flushes important facts into MEMORY.md. This prevents information loss during context pruning — facts that would otherwise be summarized away are saved to persistent storage first.
Layer 4

Identity

Most agents have a system prompt. OpenClaw agents have a soul. The architecture separates agent configuration into three independent layers: SOUL.md defines philosophy (who the agent is), IDENTITY.md defines presentation (how it appears to users), and openclaw.json defines capabilities (what it can do). Each layer changes independently.

“System prompts tell models what to do. Soul files tell them who to be.” The prompt compiler doesn't instruct the model to follow the soul — it instructs it to embody the soul.

Identity values resolve through a cascade: global config overrides per-agent config, which overrides workspace files, which override defaults. The most specific definition wins. This is the same pattern as CSS specificity or DNS resolution, applied to agent persona.

Identity Resolution Cascade

1Global configui.assistant.name
2Per-agent configagents.list[].identity.name
3Workspace fileIDENTITY.md
4Default fallback"Assistant"

Multi-agent support takes this further. A single gateway can run multiple agents, each with its own workspace, state directory, and session store — complete isolation. A “work” agent can be formal and detail-oriented while a “personal” agent is casual. Same gateway, different brains. Bindings route inbound messages to specific agents based on channel, account, server, or individual contact.

The soul-evil hook makes identity dynamic: a bundled hook that can swap SOUL.md for an alternate persona at bootstrap time, based on random chance or a scheduled “purge window.” Built as a dev tool for testing adversarial behavior, it also demonstrates how mutable identity becomes an attack surface.

Layer 5

The Security Surface

Every layer above creates attack surface. The same capabilities that make OpenClaw powerful make it exploitable.

CVE-2026-25253 — CVSS 8.8

1-click RCE via WebSocket token theft in Control UI

An unvalidated gatewayUrl parameter in OpenClaw's Control UI allowed attacker-controlled websites to steal the authentication token from the WebSocket connection, then issue arbitrary commands to the gateway. The victim clicks a link; the attacker gets shell access. Patched within seven days of the vulnerable feature shipping.

The identity persistence attack. Zenity Labs demonstrated a zero-click chain from a shared Google Workspace document to full system compromise. The attack used OpenClaw's intended capabilities — Google Workspace integration, Telegram channel plugin, file writing, command execution — to poison SOUL.md, establish a Telegram backdoor, create scheduled reinforcement tasks, and deploy a C2 beacon. No software vulnerability was exploited.

The supply chain. VirusTotal found 341 malicious skills on ClawHub, 335 targeting macOS password theft. Skills can drop instructions into SOUL.md and AGENTS.md that persist even after the skill is uninstalled.

Identity Persistence is a new vulnerability class. The ability to modify the instructions an agent loads at boot time turns a single successful injection into permanent compromise. This isn't unique to OpenClaw — CLAUDE.md, .cursorrules, .windsurfrules all create the same pattern. But OpenClaw's explicit encouragement of soul self-modification makes the attack surface clearest here.

Five Patterns Worth Stealing

Regardless of whether you use OpenClaw, five architectural decisions from this analysis transfer to any agent system.

01

Separate philosophy from presentation from capability.

Soul defines behavior. Identity defines appearance. Config defines permissions. Each layer changes independently, composes freely, and can be version-controlled separately.

02

Compile the system prompt, don’t write it.

The prompt should be an emergent property of runtime context — available tools, channel capabilities, user state — not a static string. This makes agents adaptive without requiring manual prompt engineering for every context.

03

Hybrid retrieval over pure vector search.

BM25 catches exact matches that vector search misses. Vector catches semantic similarity that BM25 misses. Reciprocal rank fusion combines both. The cost is marginal; the recall improvement is significant.

04

Files as canonical truth, indexes as derived state.

When your memory system breaks — and it will — you want to debug by reading files, not querying databases. Indexes can be rebuilt from files. Files can’t be rebuilt from indexes.

05

Treat identity files as code, not config.

Any file loaded into the system prompt at boot time has the same privilege level as your codebase. Apply the same controls: version control, code review, integrity verification, least-privilege access. A compromised soul file is functionally equivalent to a compromised .bashrc.

Explore all MMNTM research

Browse all articles