Flow 04 · CloudSwarm + R1

CloudSwarm dispatches, R1 runs.

CloudSwarm dispatches tasks. R1 agents execute them. Every R1 call routes through RelayGate so policy applies identically whether you are in Basic mode or R1-agent mode.

Request path

CloudSwarm dispatcher RelayGate shared vault shared cost accounting per-agent policy R1 agent: dentist outreach flow R1 agent: invoice reconcile flow Model providers 10 backend drivers

End-to-end call

// CloudSwarm task definition
swarm.task("dentist-outreach")
  .withAgent("r1/dentist-outreach@v2")
  .withRelay("relaygate://default")
  .run({ targetList: "leads.csv" });

// Internally, R1 agents call the model through RelayGate:
await r1.call("chat", {
  model: "claude-sonnet-4",
  messages: [...]
});
// RelayGate sees: X-CloudSwarm-Task, X-R1-Agent headers.
// Policy allows or denies per (task, agent, model).

Policy that makes it work

# swarm-policy.cel
request.headers["x-cloudswarm-task"] == "dentist-outreach"
  && request.headers["x-r1-agent"] in ["r1/dentist-outreach@v2", "r1/classify@v1"]
  && request.backend in ["anthropic-direct", "openai"]
  ? allow()
  : deny("task/agent/model combination not authorized")

Observability output

  • Shared cost accounting: every R1 agent call feeds the tenant ledger.
  • Per-task receipts: each CloudSwarm task ID rolls up the receipts of its R1 calls.
  • Shared skills registry: R1 skills are visible to CloudSwarm; CloudSwarm flows are visible to R1.

← back to flows · CloudSwarm · R1