Comprehensive tutorial series for OpenClaw AI agent gateway
Break complex tasks into specialized workers. Orchestrate multiple agents for powerful workflows.
~60 minutes for all sections
A single agent has limitations:
Sub-agents solve these:
┌──────────────┐
│ Conductor │
│ (routes & │
│ coordinates)│
└──────┬───────┘
│
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Coder │ │ Curator │ │Researcher│
│(builds) │ │(content) │ │ (gathers)│
└──────────┘ └──────────┘ └──────────┘
One agent can have multiple sessions. Sub-agents spawn new sessions.
┌─────────────┐ ┌─────────────┐
│ Parent │──── sessions_spawn ──│ Sub-Agent │
│ Session │◄──── result ─────────│ Session │
└─────────────┘ └─────────────┘
┌─────────────┐ ┌─────────────┐
│ Agent A │──── sessions_send ───│ Agent B │
│ Session │ (async msg) │ Session │
└─────────────┘ └─────────────┘
| Mode | Behavior | Use Case |
|---|---|---|
run |
Execute task, return result, terminate | One-off tasks |
start |
Start session, keep running | Long-running workers |
connect |
Join existing session | Resume previous work |
// Parent agent spawns coder sub-agent
{
"tool": "sessions_spawn",
"params": {
"agentId": "coder",
"mode": "run",
"task": "Fix the authentication bug in src/auth.ts"
}
}
// Coder does the work, returns result
// Result appears in parent's context
// Conductor sends work to coder (async)
{
"tool": "sessions_send",
"params": {
"sessionKey": "agent:coder:main",
"message": "When you have a chance, refactor the login component"
}
}
// Coder picks up message on next heartbeat
// ~/.openclaw/openclaw.json
{
agents: {
// Shared defaults
defaults: {
workspace: "~/.openclaw/workspace",
},
// Main orchestrator
main: {
model: "claude-sonnet-4-20250514",
systemPrompt: "You are a coordinator that delegates tasks.",
},
// Specialized coder
coder: {
model: "claude-sonnet-4-20250514",
workspace: "~/.openclaw/workspace-coder",
systemPrompt: "You are a coding specialist.",
tools: {
sessions_spawn: false, // Can't spawn sub-agents
},
},
// Research agent
researcher: {
model: "claude-sonnet-4-20250514",
workspace: "~/.openclaw/workspace-researcher",
systemPrompt: "You gather information and summarize findings.",
},
},
}
Each agent should have clear boundaries:
| Agent | Does | Doesn’t |
|---|---|---|
| Conductor | Coordinates, approves, user interface | Write code, browse social |
| Coder | Builds, ships, manages TODOs | Post publicly, research |
| Researcher | Gathers info for other agents | Act independently |
Create a sub-agent session for a task:
{
"tool": "sessions_spawn",
"params": {
"agentId": "coder", // Which agent to spawn
"mode": "run", // "run" | "start" | "connect"
"task": "Implement feature X", // Initial prompt
"context": { // Optional additional context
"branch": "feature/x",
"deadline": "today"
}
}
}
Send a message to an existing session:
{
"tool": "sessions_send",
"params": {
"sessionKey": "agent:coder:main", // Target session
"message": "Also add tests for that feature"
}
}
See active sessions:
{
"tool": "sessions_list",
"params": {}
}
// Returns:
// [
// { "key": "agent:coder:main", "status": "active", "lastActivity": "..." },
// { "key": "agent:researcher:main", "status": "idle", "lastActivity": "..." }
// ]
Start with Delegation Basics to learn when and how to spawn sub-agents →