camelRun by camelAIcamelRun by camelAI · AI sub-agents

Multi-agent orchestration

camelRun is camelAI's hosted runtime for AI agents. One agent fans out tasks to sub-agents and folds their answers back in.camelRun, camelAI's hosted runtime for AI agents, lets one agent fan out tasks to sub-agents. They work in parallel, and every answer folds back into its reply.

Agentresearch-lead1 of 3 answered

lead.run("Compare the three largest EV makers' 2025 margins.")

  1. → researcher · Largest by deliveriesrunning
  2. ← researcher · Second largest3 sources
  3. → researcher · Third largestrunning

The delegate tool

Fan out tasks to AI sub-agents

List the agents your agent may hand tasks to, and its model gets a delegate tool. Each call starts a sub-agent with its own tools and history, and its answer comes back as the call's result. Several calls in one response run in parallel.

research.mts
import { Agents } from "@camelai/run";

const agents = new Agents(); // reads CAMELAI_API_KEY

await agents.runtime.upsertDefinition("researcher", {
  name: "Researcher", description: "Finds sources and summarizes them",
  systemPrompt: "You research a question and answer with sources.", builtins: ["web_search", "web_fetch"],
});

const lead = await agents.upsert("research-lead", {
  instructions: "You plan research and write the report. Delegate each question to the researcher.",
  delegate: { agents: ["researcher"] },
});
const run = await lead.run("Compare the three largest EV makers' 2025 margins.");
console.log(run.text);

await agents.close();
export CAMELAI_API_KEY=art_...npm install @camelai/runnpx tsx research.mts
TooldelegateThe model sees

Hand a task to a sub-agent and wait for its answer: its final text, or with `output`, an object in that schema. The sub-agent works on its own (its own tools and history), sees only the task you give it, and its answer comes back as this call's result. Call delegate several times in one response to run tasks in parallel.

Agents you can delegate to:

- researcher: Finds sources and summarizes them

Arguments
agent
"researcher"Which agent to delegate to
task
stringThe task, with everything the sub-agent needs to know: it sees none of this conversation
output
objectA JSON Schema for an object, if you want the answer in that shape (type: "object")
Result{ agentId, requestId, status, text, output?, error? }

The agents built-in

Background AI agents that report back

Add the agents built-in, and the lead starts sub-agents and moves on. Each answer arrives as a message of its own, and wakes the lead if it's asleep.

Lead, in the background
const lead = await agents.upsert("research-lead", {
  instructions: "Start a researcher for each question, and write the report as their answers come in.",
  builtins: ["agents"], delegate: { agents: ["researcher"], maxParallel: 8 },
});
Historyresearch-leadAsleep
  1. user

    Compare the three largest EV makers' 2025 margins.

  2. research-lead
    • → spawn_agent({ agent: "researcher", task: "…" })
    • → spawn_agent({ agent: "researcher", task: "…" })
    • → spawn_agent({ agent: "researcher", task: "…" })
    • ← { agentId: "client_4be1…", name: "researcher-1" }
    • ← { agentId: "client_91c0…", name: "researcher-2" }
    • ← { agentId: "client_d27a…", name: "researcher-3" }
  3. research-lead

    Three researchers are on it. I'll write the report as their answers come in.

  4. Asleep
  5. <agent_notification name="researcher-2" status="completed">Found 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. </agent_notification></agent_notification>
  6. research-lead

    researcher-2 is in. Waiting on two more.

  7. Asleep

Inside a sub-agent

Watch every AI sub-agent work, step by step

Stream the lead with subagents: true, and every sub-agent's steps arrive as they happen. A chat made with watch: { subagents: true } shows each one as a transcript under its call, and OpenTelemetry traces nest them the same way.

Your app
<AgentChat>
Your server
lead.stream
const lead = await agents.upsert("research-lead", { delegate: { agents: ["researcher"] }, subagents: true });
for await (const part of lead.stream("…")) {
  if (part.type === "subagent_start") console.log(`→ ${part.name} (${part.agentId})`);
  if (part.type === "subagent_end") console.log(`← ${part.agentId}: ${part.status}`);
}
Output
  1. → researcher (client_6a2f9e14c07b3d85e1f4a09c7b2d6e3f8a51c0d9)
  2. → researcher (client_3f9d0b6a1c7e4f28a5d9c0b7e6f1a2d4c8b5e903)
  3. → researcher (client_b81e4c7a29f0d53e6c1a8b4f07d29e5c3a6f1b84)
  4. ← client_3f9d0b6a1c7e4f28a5d9c0b7e6f1a2d4c8b5e903: completed
  5. ← client_6a2f9e14c07b3d85e1f4a09c7b2d6e3f8a51c0d9: completed
  6. ← client_b81e4c7a29f0d53e6c1a8b4f07d29e5c3a6f1b84: completed

Settings

Set depth, parallel runs and spend for AI sub-agents

Set them once on the lead, and they cover every sub-agent it starts.

  • How deep

    maxDepth: 2

    A lead, its sub-agents and theirs. You choose how many levels.

  • How many at once

    maxParallel: 8

    You choose how many run together. The rest start as others finish.

  • How much

    spendLimit: { usd: n }

    Each sub-agent spends from the lead's budget, so one number covers the whole run.

Every sub-agent is an agent

parentAgentId

Each one is linked to its lead. Find it under the lead in the console and read its own history.

Console
Agents
NameStatus
client_5e0a8d3f71c94b2e6a0f8d17c3b59e42a6d1f083Running
↳researcherRunning
↳researcherAsleep
↳researcherRunning

Questions about multi-agent orchestration

run.textHere's how the three compare, with a source under each figure.

What are the best practices for multi-agent orchestration?

Keep one lead in charge and give each sub-agent a task that stands on its own, since it sees only its task. Describe each worker clearly and fan out independent tasks in parallel. In camelRun, depth, parallel calls and spend are settings on the lead.

What are some examples of multi-agent orchestration frameworks?

LangGraph, the OpenAI Agents SDK and CrewAI are popular frameworks for writing the orchestration in your own code. camelRun has the pattern built in: give a lead agent the delegate setting, and its sub-agents' answers come back as tool results.

What are AI subagents?

Subagents (sub-agents) are agents another agent starts to handle part of its task. In camelRun each one is a real agent with its own tools and history, linked to its lead, and its answer comes back to the lead.

How do I run parallel AI agents?

Give a lead agent the delegate setting. Several delegate calls in one response run at once, four at a time by default and more when you raise maxParallel. It's fan-out and fan-in: one call per item, and the lead combines the answers.

Can a sub-agent remember earlier tasks?

Yes. Point delegate at one of your own keyed agents, like an analyst that has covered EV makers before, and it keeps its own history from task to task. A sub-agent made from a definition starts fresh each time.

What happens to sub-agents if a server goes down?

They carry on. The lead's run resumes on another server, finds the same sub-agent and waits for its answer, so the task never runs twice.

How much do sub-agents cost?

A sub-agent is billed like any agent: $0.01 per agent-hour while it's in a run, $0.10 per GB-month of storage, and $0 for tokens on your own provider keys. What it spends counts against the lead's spend limit.

Is camelRun the CAMEL-AI multi-agent framework?

No. camelRun is camelAI's hosted runtime for AI agents, and CAMEL-AI is a separate open-source project with a similar name. camelRun is open source too, and you can host it yourself as one container and Postgres.

Run your first AI sub-agents

Get an API key and run the program above: three researchers answer, and the lead writes the report.

Set up with your coding agent

Read https://run.camelai.com/SKILL.md and set up camelRun in this project. Ask me what the agent should do.

Paste into Claude Code, Codex, Cursor or any coding agent. It asks what your agent should do, then builds it.