camelRun by camelAIcamelRun by camelAI · AI sub-agents
Multi-agent orchestration
camelRun lets a lead agent coordinate sub-agents with delegate, spawn_agent and wait_agent, or deterministic replay workflows.camelRun, camelAI's hosted runtime for AI agents, lets a lead agent coordinate sub-agents with delegate, parallel spawn_agent and wait_agent handles, or deterministic replay workflows—at $0 while the parent waits.
prompt "Compare the three largest EV makers' 2025 margins."
- → researcher · Largest by deliveriesrunning
- ← researcher · Second largest3 sources
- → researcher · Third largestrunning
The delegate built-in
Fan out tasks to AI sub-agents
Add delegate to a lead agent's builtins and it gets four orchestration tools: delegate, spawn_agent, send_message, and wait_agent. Point a call at a named definition slug, pass forkRepo: true for an isolated camelFS copy, and the parent parks at $0 until its children settle.
const BASE = "https://run.camelai.com";
const headers = { Authorization: `Bearer ${process.env.CAMELRUN_API_KEY}`, "Content-Type": "application/json" };
// 1. Register a reusable worker definition by slug.
await fetch( `${BASE}/v2/definitions/researcher`, {
method: "PUT",
headers,
body: JSON. stringify({
instructions: "You research a question and answer with cited sources.",
builtins: ["web_search", "web_fetch"],
}),
});
// 2. Enable the delegate built-in on the lead agent.
await fetch( `${BASE}/v2/agents/research-lead`, {
method: "PUT",
headers,
body: JSON. stringify({
instructions: "Plan research and delegate each company to the researcher definition.",
builtins: ["delegate"],
spendLimitUsd: 2.0,
}),
});
const res = await fetch( `${BASE}/v2/agents/research-lead/runs`, {
method: "POST",
headers,
body: JSON. stringify({ prompt: "Compare the three largest EV makers' 2025 margins.", wait: true }),
});
console. log(( await res. json()). text);export CAMELRUN_API_KEY=cr_live_...node research.ts
Synchronously delegate a task to a child agent (optionally from a named definition or on a forked camelFS repo) and return its result. The parent parks on a durable signal at $0 while the child runs.
Named worker definition:
definition: "researcher" · forkRepo?: boolean
- Arguments
- prompt
- stringTask prompt for the child agent
- definition
- string?Optional named definition slug (e.g. researcher)
- key
- string?Optional child key to reuse a child created by this parent
- forkRepo
- boolean?Copy-on-write fork of the parent's camelFS repo
Parallel handles & workflows
Run parallel children with spawn_agent and wait_agent
Use spawn_agent to launch multiple child agents concurrently and get their handles right away, send_message to steer or follow up, and wait_agent to park the parent at $0 until each child finishes—or coordinate them in code with deterministic replay workflows.
await fetch( `${BASE}/v2/agents/research-lead/workflows`, {
method: "POST",
headers,
body: JSON. stringify({
code: `const results = await Promise. all([
wf. agent({ definition: "researcher", prompt: "Largest EV maker 2025 margins" }),
wf. agent({ definition: "researcher", prompt: "Second-largest EV maker 2025 margins" }),
wf. agent({ definition: "researcher", prompt: "Third-largest EV maker 2025 margins" }),
]);
return results. map( r => r. text). join( "\n\n");`,
wait: true,
}),
});- user
Compare the three largest EV makers' 2025 margins.
- research-lead
- → spawn_agent({ definition: "researcher", prompt: "…" })
- → spawn_agent({ definition: "researcher", prompt: "…" })
- → spawn_agent({ definition: "researcher", prompt: "…" })
- ← { id: "sub_4be1c0", runId: "run_4be1c07d" }
- ← { id: "sub_91c0e6", runId: "run_91c0e6b3" }
- ← { id: "sub_d27a5f", runId: "run_d27a5f9c" }
- research-lead
Started three researchers in parallel. Waiting on each handle with wait_agent.
- Parked on wait_agent · $0
- ← wait_agent({ childId: "sub_91c0e6" }) · completedFound 3 sources: the 2025 annual report, the Q4 2025 results release and the earnings call. Both margins are in the annual report's income statement.
- research-lead
Second researcher settled. Waiting on two more handles.
- Parked on wait_agent · $0
Inside a sub-agent
Inspect every child agent's live events and history
Every delegated child is a full v2 agent with its own childKey and runId. Stream the lead from GET /v2/agents/research-lead/events?after=0, and open any child's SSE stream or paged history in your own UI to follow every step.
// Watch the lead's v2 SSE stream (resumes cleanly with ?after=<seq>):
const res = await fetch( `${BASE}/v2/agents/research-lead/events?after=0`, {
headers: { Authorization: `Bearer ${process.env.CAMELRUN_API_KEY}`, Accept: "text/event-stream" },
});
// Inspect any child's full history or live events by its childKey:
// GET /v2/agents/research-lead__sub_2/history?after=0&limit=50- → delegate (research-lead__sub_1 · run_2f7c1a9e)
- → delegate (research-lead__sub_2 · run_8c1e5a7f)
- → delegate (research-lead__sub_3 · run_e4b09d2c)
- ← research-lead__sub_2: completed
- ← research-lead__sub_1: completed
- ← research-lead__sub_3: completed
Orchestration controls
Isolated repos, parallel handles, and shared spend caps
Combine synchronous delegate, async spawn_agent + wait_agent, and deterministic replay workflows—with copy-on-write repo isolation and one budget cap.
Every child is a full v2 agent
childKey · agt_…Each child runs in its own SQLite Durable Object with its own history and camelFS files. Inspect it in the console or read GET /v2/agents/:childKey/history.
| Name | Type | Status |
|---|---|---|
| research-lead | lead | Running |
| ↳research-lead__sub_1 | researcher | Running |
| ↳research-lead__sub_2 | researcher | Asleep |
| ↳research-lead__sub_3 | researcher | Running |
Questions about multi-agent orchestration
run.textHere's how the three compare, with a source under each figure.
When should I use delegate, spawn_agent and wait_agent, or a workflow?
Use delegate for one task the lead needs before it can continue. Start parallel children with spawn_agent, steer them with send_message, and collect results with wait_agent. Use the workflows API for deterministic replay.
What are some examples of multi-agent orchestration frameworks?
LangGraph, the OpenAI Agents SDK, and CrewAI orchestrate agents in your application. camelRun can host the agents with persisted history and durable waits when you enable the delegate or workflows built-in.
What are AI subagents?
They're agents started by a lead with the delegate built-in. Each child has its own instructions, tools, and history. It can use a named definition or inline instructions and fork the lead's workspace.
How do parallel sub-agents avoid conflicting on workspace files?
Pass forkRepo: true to delegate or spawn_agent. Each child gets a copy-on-write fork of the parent's camelFS repo and can edit files or run bash independently.
Can a sub-agent remember earlier tasks?
Yes. Pass an existing child key to delegate or spawn_agent to keep that child's history and files. The key must belong to the same parent. Omitting it creates a fresh child.
What happens to delegated sub-agents if a worker restarts?
Both delegate and wait_agent give the parent a durable wait across restarts without polling. When the child settles, the parent wakes and reads its saved result. Aborting the parent aborts its active child.
How much do sub-agents cost?
Each child costs $0.05 per active agent-hour and $0 while idle, queued, or parked. Linux containers cost $0.00005/sec ($0.18/hr) while active, with free pre-warming. Storage is unmetered. Use your own model keys or pay the provider's token price with no markup. Child spend counts against the parent's spendLimitUsd.
Is camelRun the CAMEL-AI multi-agent framework?
camelRun by camelAI is an AGPL-3.0 runtime for AI agents. You can host it yourself in your Cloudflare account with Wrangler or try experimental self-hosting with celld. CAMEL-AI is a separate project.
Keep reading
More on AI sub-agents
- camelRunThe hosted runtime for AI agents.
- MCP agentsConnect agents to remote HTTP MCP tools. Use the hosted MCP server at /mcp with OAuth 2.1 or connect to one agent at /v2/agents/:key/mcp.
- Code mode for AI agentsRun model-written JavaScript in a QuickJS sandbox that can call tools, including remote MCP tools. Agents can also run bash in a Linux container.
- Durable AI agentsKeyed agents keep their history, versioned camelFS workspaces, and pending runs in camelRun. Fork any agent and its repo instantly at any step (atSeq).
- LangGraph Platform alternativeImport threads, files, and schedules from LangGraph Agent Server into camelRun with a one-way importer. Each imported thread becomes a keyed agent.
- Human-in-the-loop AI agentsPause a run for an approval or answer and resume when the person responds. Waiting for input costs $0 in agent time.
- Background AI agentsWake an agent on a schedule or with an HTTP webhook. It keeps its history and files between runs and costs $0 in agent time while idle.
Run your first AI sub-agents
Create a cr_live_ API key and run research.ts: three researchers run in parallel and the lead compiles the report.
claude mcp add --transport http camelrun https://run.camelai.com/mcp
Adds camelRun's hosted MCP server to Claude Code (also works with Codex and ChatGPT). Signing in creates your account automatically.