OpenClaw for AI Agent Development: Complete Guide to Multi-Channel Agent Gateways
Building AI agents that respond across WhatsApp, Telegram, Discord, and iMessage used to mean maintaining separate infrastructure for each platform. OpenClaw changes that. It's a self-hosted gateway that unifies every messaging channel under one roof, giving your agents a single point of control for multi-platform deployment.
If you're running autonomous agents—coding bots, customer service assistants, research agents—OpenClaw is the missing infrastructure layer between your AI logic and the real world. Here's everything you need to know.
What OpenClaw Solves
The problem: You've built an agent that works brilliantly via API. Now you want users to message it on WhatsApp, Telegram, Discord, and iMessage. Without OpenClaw, you're building four separate integrations, each with its own authentication, message handling, media processing, and session management.
The OpenClaw solution: Run one Gateway process. Connect all your channels to it. Your agent receives normalized messages regardless of source. Reply once, and OpenClaw routes it to the right platform automatically.
This matters because:
- Development speed: Build one agent, deploy everywhere
- Maintenance: Update agent logic in one place, not per channel
- Session management: Unified conversation history across platforms
- Self-hosted: Your data stays on your infrastructure
Core Architecture
OpenClaw uses a hub-and-spoke model:
WhatsApp →
Telegram → GATEWAY → Your AI Agent
Discord → ↓
iMessage → Tool Calls, Memory, Sessions
The Gateway handles:
- Channel connections (OAuth, QR codes, bot tokens)
- Message normalization (turn platform-specific formats into unified structure)
- Session routing (map conversations to agent instances)
- Tool execution (file access, command execution, browser control)
- Media processing (images, voice notes, documents)
Installation and Setup
Quick Start (5 minutes)
Install OpenClaw globally via npm:
npm install -g openclaw@latest
Run the onboarding wizard:
openclaw onboard --install-daemon
This walks you through:
Pair WhatsApp:
openclaw channels login
Scan the QR code with WhatsApp, and you're live.
Start the Gateway:
openclaw gateway --port 18789
Open the Control UI at http://localhost:18789 to see sessions, send messages, and manage config.
Production Deployment
For production environments, run OpenClaw as a system service:
macOS (launchd):
openclaw daemon install
openclaw daemon start
Linux (systemd):
openclaw daemon install --systemd
sudo systemctl enable openclaw-gateway
sudo systemctl start openclaw-gateway
Docker:
docker run -d \
-p 18789:18789 \
-v ~/.openclaw:/root/.openclaw \
--name openclaw-gateway \
openclaw/gateway:latest
The Gateway runs as a background process, restarting automatically on crashes or reboots.
Channel Configuration
OpenClaw supports 15+ messaging platforms. Here's how to configure the most common ones:
WhatsApp uses a local client that pairs via QR code. No Business API required—this is your personal WhatsApp account acting as a bot.
openclaw channels login
Scan the QR code. Messages start flowing immediately.
Security tip: Use allowFrom to restrict who can message your agent:
{
"channels": {
"whatsapp": {
"allowFrom": ["+15555550123", "+15555550124"],
"groups": {
"*": { "requireMention": true }
}
}
}
}
This blocks unknown numbers and requires @mentions in group chats.
Telegram
Telegram requires a bot token from @BotFather:
/newbot and follow prompts123456789:ABCdefGHIjklMNOpqrsTUVwxyz)Configure OpenClaw:
openclaw channels add telegram --token YOUR_BOT_TOKEN
Or edit ~/.openclaw/openclaw.json:
{
"channels": {
"telegram": {
"enabled": true,
"token": "123456789:ABCdefGHIjklMNOpqrsTUVwxyz"
}
}
}
Restart the Gateway. Users can now message your bot on Telegram.
Discord
Discord bots need an application + bot token:
Add to OpenClaw:
openclaw channels add discord --token YOUR_DISCORD_BOT_TOKEN
Invite the bot to servers using the OAuth2 URL generator (select bot scope + Send Messages, Read Messages, Attach Files permissions).
iMessage
iMessage integration requires macOS and uses AppleScript bridging:
openclaw channels add imessage
OpenClaw sends/receives messages via the Messages app. This only works on Mac—Linux and Windows users need BlueBubbles as a bridge.
BlueBubbles alternative: For non-Mac hosts, run BlueBubbles on a Mac server and connect OpenClaw to it:
{
"channels": {
"bluebubbles": {
"enabled": true,
"url": "http://your-mac-server:1234",
"password": "your-bluebubbles-password"
}
}
}
Multi-Agent Routing
One Gateway can run multiple agents simultaneously, each with isolated sessions. This is critical for production deployments where different users or teams need dedicated agent instances.
Per-Sender Sessions
Default behavior: each sender gets their own session.
User A on WhatsApp → Session 1 (Agent: Claude)
User B on Telegram → Session 2 (Agent: Claude)
User C on Discord → Session 3 (Agent: Claude)
Each conversation maintains separate context, memory, and tool state.
Per-Channel Agents
Route channels to different agents:
{
"agents": {
"whatsapp": {
"agentId": "coding-assistant",
"model": "anthropic/claude-sonnet-4"
},
"telegram": {
"agentId": "research-agent",
"model": "openai/gpt-4-turbo"
}
}
}
WhatsApp users talk to a coding agent; Telegram users get a research agent.
Workspace Isolation
For team deployments, isolate agents by workspace:
{
"workspaces": {
"engineering": {
"channels": ["telegram", "discord"],
"agentId": "code-reviewer",
"allowFrom": ["@engineering-team"]
},
"support": {
"channels": ["whatsapp"],
"agentId": "customer-support",
"allowFrom": ["+1555*"]
}
}
}
Each workspace has its own agent, allowed users, and channel access.
Tool Integration
OpenClaw agents aren't chatbots—they're autonomous systems with access to your environment. Tools unlock this capability.
File System Access
Agents can read, write, and edit files in their workspace (~/.openclaw/workspace by default):
User: Read src/main.py and fix the syntax error
Agent: [reads file via `read` tool]
Agent: [edits file via `edit` tool]
Agent: Fixed. The missing colon on line 42 is now corrected.
Security: Tools run in a sandbox by default. Enable elevated mode for system-wide access:
openclaw gateway --elevated
Use with caution—agents can now modify any file you can access.
Shell Command Execution
The exec tool runs shell commands:
User: What's the status of the API server?
Agent: [executes `systemctl status api-server`]
Agent: The API server is running (PID 1234). Uptime: 3 days, 2 hours.
PTY support: For interactive commands (like vim or ssh), use PTY mode:
exec({
command: "ssh user@server",
pty: true
})
This allocates a pseudo-terminal, enabling full TTY interactions.
Browser Control
OpenClaw includes a headless Chromium browser for web automation:
User: Check the latest price on example.com/products/widget
Agent: [opens browser via `browser` tool]
Agent: [navigates to URL]
Agent: [takes screenshot]
Agent: The price is $49.99 (down from $59.99).
Browser actions include:
navigate- go to URLclick- click element by selectortype- enter text in input fieldsscreenshot- capture pageevaluate- run JavaScript
Example: Automated form filling
browser({
action: "act",
request: {
kind: "fill",
fields: [
{ selector: "#email", value: "[email protected]" },
{ selector: "#message", value: "Hello from OpenClaw" }
],
submit: true
}
})
Web Fetch and Search
For lightweight data retrieval, use web_fetch and web_search:
User: Summarize the latest post on blog.example.com
Agent: [fetches URL via `web_fetch`]
Agent: [extracts readable content]
Agent: The article discusses three new features...
web_search uses Brave Search API for web queries:
User: Find the top 5 results for "AI agent frameworks"
Agent: [calls `web_search` with query]
Agent: Here are the top results: ...
Memory and Session Management
Agents need memory to maintain context across conversations. OpenClaw provides multiple layers:
Short-Term Memory (Session Transcript)
Every message in a session is stored in the transcript. Agents see the full conversation history on each turn.
Compaction: Long transcripts get summarized automatically to stay within context limits. The Gateway uses Claude's compaction to condense older messages while preserving critical info.
Long-Term Memory (Workspace Files)
Agents persist knowledge by writing to files in their workspace:
~/.openclaw/workspace/
├── MEMORY.md # Long-term facts and learnings
├── AGENTS.md # Agent behavior config
├── TOOLS.md # Lookup tables and references
├── memory/
│ └── 2026-03-07.md # Daily logs
Best practice: Agents should write important facts to MEMORY.md and daily notes to memory/YYYY-MM-DD.md. This creates a searchable knowledge base that survives session resets.
Memory Search
The memory_search tool enables semantic search across all memory files:
User: What did we decide about database schema last week?
Agent: [searches memory files for "database schema"]
Agent: [finds entry from 2026-02-28.md]
Agent: You decided to use PostgreSQL with normalized tables...
Cron Jobs and Automation
Agents can schedule recurring tasks using cron jobs:
openclaw cron add \
--name "Daily Report" \
--schedule "0 9 * * *" \
--task "Generate daily metrics report and send to Telegram"
This runs every day at 9 AM. The agent executes the task in an isolated session and optionally delivers results to a specified channel.
Cron vs Heartbeat:
- Cron: Scheduled tasks (fixed times)
- Heartbeat: Periodic checks (every N minutes, on-demand logic)
Use cron for "every Monday at 8 AM" tasks. Use heartbeat for "check email inbox every 30 minutes" flows.
Example: Automated Code Review
{
"name": "PR Review",
"schedule": {
"kind": "cron",
"expr": "0 */2 * * *"
},
"payload": {
"kind": "agentTurn",
"message": "Check GitHub for new pull requests. Review code quality and post comments."
},
"sessionTarget": "isolated"
}
Every 2 hours, the agent checks PRs and posts reviews automatically.
Advanced Patterns
Sub-Agents and Task Delegation
Spawn isolated sub-agents for complex tasks:
sessions_spawn({
task: "Research competitors and write a 2-page analysis",
cleanup: "delete",
runTimeoutSeconds: 600
})
The sub-agent runs in its own session, completes the task, and returns results. The parent agent never sees the intermediate steps—only the final output.
Use cases:
- Long-running research tasks
- Parallel data processing
- Background report generation
Webhook Integration
Trigger agents via HTTP webhooks:
curl -X POST http://localhost:18789/webhooks/my-agent \
-H "Content-Type: application/json" \
-d '{"event": "new_signup", "user": "[email protected]"}'
The agent receives the webhook payload as a message and processes it accordingly.
Mobile Nodes (iOS and Android)
Pair mobile devices as "nodes" to access phone capabilities:
- Camera: Capture photos or video on command
- Screen recording: Record device screen for tutorials
- Location: Get GPS coordinates
- Notifications: Send push notifications
openclaw nodes pairing create
Scan the code with the OpenClaw mobile app. The node appears in openclaw nodes list.
Request a camera snap:
nodes({
action: "camera_snap",
node: "iphone-pro",
facing: "back",
quality: 0.9
})
The agent receives the photo and can analyze it, send it elsewhere, or store it.
Security Best Practices
Authentication and Allowlists
Always restrict access in production:
{
"security": {
"tokens": {
"gateway": "your-secret-token-here"
}
},
"channels": {
"whatsapp": {
"allowFrom": ["+15555550123"]
},
"telegram": {
"allowedUsers": [123456789]
}
}
}
Without allowlists, anyone who finds your bot can send it commands.
Secrets Management
Store API keys in ~/.openclaw/secrets.json, not in config:
{
"anthropic_key": "sk-ant-...",
"github_token": "ghp_..."
}
Reference secrets in config:
{
"providers": {
"anthropic": {
"apiKey": "$anthropic_key"
}
}
}
OpenClaw resolves $variable references at runtime.
Sandbox vs Elevated Mode
Sandbox mode (default):
- Agent runs in isolated workspace
- Can only access
~/.openclaw/workspace - Cannot modify system files
Elevated mode:
- Agent has full file system access
- Can run
sudocommands - Can modify system configs
Use elevated mode only when necessary. For most tasks, sandbox is sufficient and much safer.
Performance Optimization
Prompt Caching
For providers that support it (Anthropic, OpenAI), enable prompt caching:
{
"inference": {
"promptCaching": true
}
}
This caches system prompts and agent instructions, reducing API costs by 50-90% for repeated interactions.
Model Failover
Configure fallback models for reliability:
{
"providers": {
"primary": {
"model": "anthropic/claude-sonnet-4",
"maxRetries": 3
},
"fallback": {
"model": "openai/gpt-4-turbo",
"enabled": true
}
}
}
If Claude is down, OpenClaw automatically switches to OpenAI.
Session Compaction
Long conversations burn tokens. Enable auto-compaction:
{
"sessions": {
"compaction": {
"enabled": true,
"maxTokens": 100000
}
}
}
When transcript exceeds 100k tokens, OpenClaw summarizes older messages to stay within limits.
Deployment Patterns
Single-User Personal Assistant
Run OpenClaw on your laptop with one agent for all channels:
openclaw gateway --port 18789
You message it on WhatsApp, Telegram, or Discord—same agent, same memory.
Multi-Tenant SaaS
Deploy one Gateway per customer:
Customer A → Gateway A (port 18789)
Customer B → Gateway B (port 18790)
Customer C → Gateway C (port 18791)
Each Gateway has isolated config, sessions, and workspace.
High-Availability Cluster
For production services, run multiple Gateways behind a load balancer:
Load Balancer
├─ Gateway 1 (with sticky sessions)
├─ Gateway 2
└─ Gateway 3
Use Redis for shared session storage across instances.
Troubleshooting Common Issues
WhatsApp QR Code Expired
Re-pair from scratch:
openclaw channels logout whatsapp
openclaw channels login
Telegram Bot Not Responding
Check bot token and privacy settings:
openclaw gateway restartHigh Memory Usage
Enable session pruning:
{
"sessions": {
"pruning": {
"enabled": true,
"maxAgeDays": 30
}
}
}
Old sessions get archived automatically.
Tools Not Working
Verify tool policy:
openclaw status
Check "Tool Policy" line. If it says "Sandbox", elevated tools won't work. Run with --elevated if needed.
Next Steps
Start here:
npm install -g openclaw@latestopenclaw onboardopenclaw channels loginThen explore:
- Skills documentation for custom tools
- Multi-agent routing for advanced setups
- ClawHub for community-built skills and plugins
OpenClaw is infrastructure. Your agent is the application. Build something autonomous.
Resources: