Guides
Multi-agent delegation and coordination in camelRun v2
Delegate work to child agents synchronously or asynchronously using the delegate built-in suite, definitions, and forked repositories.
In camelRun v2, a parent agent can delegate tasks to specialist child agents using the delegate built-in suite, or your application code can coordinate multiple keyed agents directly.
Enabling delegation (builtins: ["delegate"])
First, optionally create reusable definitions for specialist workers, then enable "delegate" on the lead agent:
await client.definitions.upsert("code-reviewer", {
model: "anthropic/claude-sonnet-4-0",
instructions: "Review diffs for correctness, security, and edge cases. Be concise.",
builtins: ["files"],
});
const lead = await client.agents.upsert("engineering-lead", {
model: "azure/gpt-6.1-terra",
instructions: "Plan changes, delegate code reviews to the code-reviewer definition, and summarize findings.",
builtins: ["files", "bash", "delegate"],
repoId: repo.repoId,
});
const run = await lead.run("Inspect src/auth.ts and have code-reviewer audit it.");
console.log(run.text);Delegation tools
Enabling builtins: ["delegate"] exposes four tools to the parent agent:
| Tool | Behavior | Parameters |
|---|---|---|
delegate | Starts a child agent run, waits for it to finish, and returns its output synchronously. | prompt (required), definition?, key?, model?, instructions?, forkRepo? |
spawn_agent | Starts an asynchronous child agent run and returns a handle (childId, childAgentId, runId) immediately so the parent can spawn multiple workers in parallel. | prompt (required), definition?, key?, model?, instructions?, forkRepo? |
send_message | Sends a follow-up prompt or mid-turn steer (whileRunning: "queue" | "steer") to a spawned child agent. | childId (required), prompt (required), whileRunning? |
wait_agent | Waits for an asynchronous child agent run to complete and returns its result. | childId (required), runId? |
Forking repositories for child agents (forkRepo: true)
Pass forkRepo: true (or instruct the lead agent to use it) when a child agent should experiment on an isolated copy of the parent's CamelFS repository without mutating the parent's working branch. camelRun forks the parent's lineage for the child agent automatically.
Coordinating agents from your own code
Because every agent is addressed by key, you can run independent agents in parallel from your backend with Promise.all:
const [billingAgent, infraAgent] = await Promise.all([
client.agents.upsert("triage-billing", { definition: "billing-specialist" }),
client.agents.upsert("triage-infra", { definition: "infra-specialist" }),
]);
const [billingRun, infraRun] = await Promise.all([
billingAgent.run("Check whether invoice #402 is overdue."),
infraAgent.run("Check whether EU-west latency spiked in the last hour."),
]);For multi-step orchestration with deterministic replay caching across retries, use Workflows.