Gateway architecture
One long-running process manages multiple channels and multiple agents simultaneously.
A comprehensive guide to sessions, memory, agents, channels, and orchestration — the building blocks of an AI agent runtime.
OpenClaw is an AI agent runtime that connects large language models to messaging channels. Think of it as an operating system for agents — not a chatbot framework.
Gateway architecture
One long-running process manages multiple channels and multiple agents simultaneously.
Multi-tenant
Each agent is fully isolated — own workspace, own state, own sandbox.
Not a chatbot
Agents can exec shell commands, browse the web, read/write files, manage calendars, and more.
# Start the gatewayopenclaw gateway start
# It manages:# → Channels (WhatsApp, Telegram, Discord, …)# → Agents (each with own workspace)# → Sessions (conversation contexts)# → Tools (exec, browser, read, write, …)A session is the conversation context an agent holds with a user or group. It includes the full message history and any accumulated state.
Every session has a unique key that determines its scope:
// DM session keyagent:<agentId>:<mainKey>// Example: agent:jarvis:whatsapp:peer:31612345678
// Group session keyagent:<agentId>:<channelType>:channel:<channelId>// Example: agent:jarvis:discord:channel:123456789| Event | Description |
|---|---|
| Daily reset | Sessions automatically reset at 4 AM (configurable) to prevent context bloat. |
| Idle reset | After a period of inactivity, sessions may be garbage-collected. |
| Manual reset | Users can type /new or /reset to start fresh. |
main
Shared session across all DM channels for this peer.
per-peer
One session per peer, regardless of channel.
per-channel-peer
Separate session for each channel × peer combination.
Sessions are persisted as JSONL transcripts (one JSON object per line, per message) alongside a sessions.json store that tracks metadata.
state/├── sessions.json // Session metadata & keys└── transcripts/ └── <session-key>.jsonl // Full message historyMemory in OpenClaw is refreshingly simple: it’s just files. The agent reads and writes plain Markdown files. No special database, no proprietary format.
MEMORY.md
Long-term memory — relationship context, user preferences, persistent facts. The agent updates this file as it learns.
memory/YYYY-MM-DD.md
Daily logs — what happened today. Auto-created, one file per day. Great for temporal queries (“what did we discuss yesterday?”).
workspace/├── MEMORY.md // Long-term memory└── memory/ ├── 2025-01-15.md // Daily log ├── 2025-01-16.md └── ...An agent is a workspace + state directory + sessions. Each agent has its own personality, tools, memory, and conversation history — fully isolated from other agents.
| File | Purpose |
|---|---|
AGENTS.md | How the workspace works |
SOUL.md | Agent personality & identity |
USER.md | Info about the primary user |
IDENTITY.md | Name, model, appearance |
TOOLS.md | Tool usage notes |
BOOTSTRAP.md | First-run instructions |
Bindings determine which agent handles which messages. They match on channel type, account ID, and peer patterns.
// gateway.json5 bindings example{ agents: { jarvis: { bindings: [ { channel: "whatsapp", accountId: "31612345678" }, { channel: "discord", accountId: "bot-token-id" }, { channel: "telegram", peer: "jonas_*" }, // Peer pattern matching ] } }}Skills extend what an agent can do:
skills/ directory.Channels are how agents communicate with the outside world. Each channel connects to the Gateway and routes messages to the appropriate agent via bindings.
Telegram
Discord
Slack
Signal
iMessage
Web Chat
The end-to-end path of a message through the system:
Message → Channel → Gateway → Binding → Agent → Session → LLM → Response
Agents can spawn sub-agents via sessions_spawn for background tasks — research, long-running computations, or parallel work. Results are automatically reported back to the parent agent.
# Tools available to agentsexec # Run shell commandsread # Read fileswrite # Write filesbrowser # Control web browserweb_search # Search the webmessage # Send messages to channelsnodes # Control paired devicescanvas # Present UI to users