Lesson 2 of 4 · OpenClaw Mastery: Build Your AI Assistant
Architecture Overview: Gateway, Agents, and Skills
Architecture Overview: Gateway, Agents, and Skills
Before you write a single line of configuration, you need a mental model of how OpenClaw actually works under the hood. This isn't academic navel-gazing -- understanding the architecture will save you hours of debugging later and let you build more sophisticated automations from day one.
Think of OpenClaw like a well-organized company. There's a CEO (the Gateway) who receives all incoming requests, employees (Agents) who process those requests using their expertise, and tools (Skills) that employees use to get work done.
Let's break each one down.
The Gateway: OpenClaw's Brain
The Gateway is the central nervous system of your OpenClaw deployment. It's a WebSocket-based control plane that listens on port 18789 by default and handles everything:
- Message routing -- Receives incoming messages from any connected channel (WhatsApp, Telegram, Slack, etc.) and routes them to the appropriate agent
- State management -- Tracks conversation context, user sessions, and agent states
- Skill execution -- Orchestrates skill calls and returns results
- Model coordination -- Sends prompts to your configured AI model(s) and handles responses
┌─────────────────────────────────────────────────────────┐
│ THE GATEWAY (port 18789) │
│ │
│ ┌──────────┐ ┌──────────────┐ ┌───────────────────┐ │
│ │ Message │ │ State │ │ Skill │ │
│ │ Router │ │ Manager │ │ Executor │ │
│ └──────────┘ └──────────────┘ └───────────────────┘ │
│ │
│ ┌──────────┐ ┌──────────────┐ ┌───────────────────┐ │
│ │ WebSocket │ │ Model │ │ Plugin │ │
│ │ Server │ │ Coordinator │ │ Manager │ │
│ └──────────┘ └──────────────┘ └───────────────────┘ │
└─────────────────────────────────────────────────────────┘
▲ ▲ ▲
│ │ │
┌────┘ ┌─────────┘ ┌─────────┘
│ │ │
┌───┴───┐ ┌──┴──┐ ┌──────┴──────┐
│Channels│ │Models│ │ Skills │
│WhatsApp│ │GPT-4│ │ Web Browse │
│Telegram│ │Claude│ │ Email Send │
│ Slack │ │Ollama│ │ File Mgmt │
│Discord │ │ etc. │ │ Smart Home │
└────────┘ └──────┘ └─────────────┘OpenClaw uses WebSocket instead of HTTP REST for its control plane because conversations are inherently bidirectional and real-time. When you send a message on WhatsApp, you expect a response -- possibly with follow-up questions, status updates, or streaming output. WebSocket makes this natural. The Gateway maintains persistent connections with all clients and can push events at any time, not just in response to requests.
Agents: The Workers
An Agent in OpenClaw is a configured AI persona that handles conversations. Think of agents as specialized employees -- each one can have:
- A specific AI model (GPT-4, Claude, Llama, Mistral, etc.)
- A system prompt defining its personality and behavior
- A set of enabled skills determining what actions it can take
- Memory configuration controlling how much context it retains
- Channel assignments specifying which messaging platforms it serves
Here's a simplified agent configuration:
You can run multiple agents simultaneously, each with different models, skills, and personalities. One agent might handle your personal messages on Telegram while another handles customer support on WhatsApp.
56+
Built-in skills
OpenClaw ships with over 56 ready-to-use skills across communication, web, productivity, smart home, development, media, and data categories.
The Pi Agent Runtime
Under the hood, each agent runs inside OpenClaw's Pi agent runtime -- a conversation management layer that handles:
- Context window management -- Intelligently summarizes and compresses conversation history to stay within model token limits
- Skill selection -- Determines which skills are relevant to the current request
- Tool calling -- Formats and executes skill calls based on model output
- Response formatting -- Adapts responses for the target messaging platform (e.g., Markdown for Telegram, plain text for SMS)
Use Architecture Overview: Gateway, Agents, and Skills in a low-risk branch or scratch project first. That keeps the lesson concrete without making your first attempt carry production pressure.
The Pi runtime is what makes OpenClaw feel intelligent rather than just reactive. It maintains conversational context, remembers user preferences within a session, and chains multiple skill calls together to accomplish complex tasks.
Skills: The Abilities
Skills are modular capabilities that give your agents the power to interact with the real world. OpenClaw ships with 56+ built-in skills organized into categories:
| Category | Example Skills | What They Do |
|---|---|---|
| Communication | Email, SMS | Send/receive emails and text messages |
| Web | Web Browse, Web Search | Browse websites, extract data, search the internet |
| Productivity | Calendar, Notes, Reminders | Manage schedules and information |
| Files | File Manager, Cloud Storage | Read, write, organize files |
| Smart Home | Home Assistant, IoT | Control lights, thermostats, cameras |
| Development | Git, Terminal, Code Runner | Execute code and dev workflows |
| Media | Image Gen, Audio, Video | Generate and process media |
| Data | Database, Spreadsheet, API | Query databases and call APIs |
Add One Architecture Overview: Gateway, Agents, and Skills Connection
- Choose one external system that would genuinely improve this lesson's workflow.
- Configure an MCP server or inspect the one your team already uses.
- Ask Claude to call exactly one tool from that server and verify the result is useful.
Each skill is defined by a SKILL.md file -- a structured markdown document that tells the AI model what the skill can do, what parameters it accepts, and how to call it. This is one of OpenClaw's most elegant design decisions: skills are described in natural language that both humans and AI models can understand.
Here's what a simplified SKILL.md looks like:
The skill system is what transforms OpenClaw from "another chatbot" into a genuine assistant. When you ask OpenClaw "Is it going to rain in Portland tomorrow?", the Gateway routes your message to an agent, the agent's AI model reads the Weather skill description, decides to call get_forecast with location: "Portland" and days: 1, receives the API response, and formulates a natural language answer. All of this happens in seconds.
How Messages Flow: The Complete Pipeline
Let's trace a message from the moment you type it on WhatsApp to the moment you receive a response. Understanding this flow is essential for debugging and optimization.
You type on WhatsApp: "Turn off the living room lights"
│
▼
┌──────────────────────────────┐
│ 1. WhatsApp Channel Adapter │ ← Receives message via WhatsApp Business API
│ Normalizes to internal │
│ message format │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ 2. Gateway Message Router │ ← Identifies user, selects appropriate agent
│ Routes to assigned agent │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ 3. Pi Agent Runtime │ ← Loads conversation context and history
│ Prepares context window │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ 4. AI Model (e.g., GPT-4) │ ← Receives system prompt + context + message
│ Decides to use skill │ Returns: call smart_home.toggle_device
│ │ params: {device: "living_room_lights",
│ │ action: "off"}
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ 5. Skill Executor │ ← Validates params, calls Home Assistant API
│ Executes smart_home │ Returns: {success: true}
│ skill │
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ 6. AI Model (second pass) │ ← Receives skill result
│ Generates human response │ Returns: "Done! Living room lights are
│ │ now off."
└──────────────┬───────────────┘
│
▼
┌──────────────────────────────┐
│ 7. WhatsApp Channel Adapter │ ← Formats response for WhatsApp
│ Sends response back │ Delivers to your phone
└──────────────────────────────┘The entire round-trip typically takes 2-5 seconds, depending on your AI model's response time and the complexity of the skill execution.
The slowest part of this pipeline is almost always the AI model inference (step 4 and 6). If you're using a cloud model like GPT-4, expect 1-3 seconds per inference call. For complex requests requiring multiple skill calls, latency compounds. We'll cover optimization strategies in later chapters, including model routing (use a fast model for simple tasks, a powerful model for complex ones).
The Plugin Architecture
Beyond built-in skills, OpenClaw supports a robust plugin system. Plugins can:
- Add new messaging channel adapters
- Register custom skills
- Modify message processing pipelines
- Add middleware (logging, rate limiting, content filtering)
- Integrate with external services
Quick Check
What is the main benefit of using Architecture Overview: Gateway, Agents, and Skills well in Claude Code?
The ClawHub marketplace is where the community shares plugins and skills. Think of it like npm for AI assistant capabilities -- you can install a "Spotify Controller" skill, a "Jira Ticket Manager" skill, or a "Recipe Finder" skill with a single command.
Putting It All Together
Here's the mental model to carry with you through the rest of this course:
- Gateway = The central hub. Everything connects here. It runs on port 18789 and manages the entire system.
- Agents = AI personas with specific models, prompts, skills, and channel assignments. You can have many.
- Skills = Modular abilities defined by SKILL.md files. They give agents the power to interact with external services.
- Channels = Messaging platforms (WhatsApp, Telegram, etc.) that connect users to agents.
- Pi Runtime = The conversation engine inside each agent that manages context, selects skills, and chains actions.
Try This Now
Let's solidify your understanding of the architecture by designing a system on paper:
- Sketch the Gateway diagram from this lesson on a whiteboard or paper. Don't copy it -- redraw it from memory. What did you miss?
- Design two agents for your personal use:
- Agent A: What model would it use? What skills does it need? Which messaging channel?
- Agent B: Make it different from Agent A -- different purpose, different channel.
- Trace a message through the full pipeline for this scenario: You send a Telegram message saying "Email my boss the Q3 report and add a meeting to my calendar for Friday at 2pm to discuss it." How many skill calls are needed? What's the order?
Write down your answers -- we'll refine this design as you learn more in upcoming lessons.
Key Takeaways
- The Gateway is OpenClaw's central control plane -- a WebSocket server on port 18789 that routes messages, manages state, and orchestrates skill execution
- Agents are configurable AI personas, each with their own model, system prompt, enabled skills, and channel assignments
- Skills are modular capabilities defined by SKILL.md files -- OpenClaw ships with 56+ built-in skills covering communication, web, productivity, smart home, and more
- The Pi agent runtime manages conversation context, skill selection, and tool calling within each agent
- Messages flow through a 7-step pipeline: Channel --> Router --> Context --> AI Model --> Skill Executor --> AI Model --> Channel
- The ClawHub marketplace lets you install community-built skills and plugins
- Latency is primarily determined by AI model inference time (1-3 seconds per call for cloud models)
Use ← → to navigate, Space to mark complete