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.

Agentresearch-lead1 of 3 answered

prompt "Compare the three largest EV makers' 2025 margins."

  1. → researcher · Largest by deliveriesrunning
  2. ← researcher · Second largest3 sources
  3. → 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.

research.ts
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
TooldelegateThe model sees

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
Result{ id, childAgentId, childKey, runId, status, text, output, filesChanged }

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.

Deterministic replay workflow · POST /v2/agents/:key/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,
  }),
});
Historyresearch-leadAsleep
  1. user

    Compare the three largest EV makers' 2025 margins.

  2. 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" }
  3. research-lead

    Started three researchers in parallel. Waiting on each handle with wait_agent.

  4. Parked on wait_agent · $0
  5. ← 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.
  6. research-lead

    Second researcher settled. Waiting on two more handles.

  7. 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.

Your app
v2 SSE UI
Your server
/v2/agents/.../events
// 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
Output
  1. → delegate (research-lead__sub_1 · run_2f7c1a9e)
  2. → delegate (research-lead__sub_2 · run_8c1e5a7f)
  3. → delegate (research-lead__sub_3 · run_e4b09d2c)
  4. ← research-lead__sub_2: completed
  5. ← research-lead__sub_1: completed
  6. ← 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.

  • Forked repos

    forkRepo: true

    Give each child an instant copy-on-write fork of the parent's camelFS workspace so parallel edits never collide.

  • Async fan-out

    spawn_agent + wait_agent

    Launch child agents in parallel, follow up with send_message, and park on wait_agent at $0 until each run settles.

  • Shared budget

    spendLimitUsd

    Set spendLimitUsd on the parent agent or run. Delegated children reserve and draw from what remains of that 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.

Console
Agents
NameStatus
research-leadRunning
↳research-lead__sub_1Running
↳research-lead__sub_2Asleep
↳research-lead__sub_3Running

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.

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.

Connect your coding agent (no key)

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.