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.
// 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).
# 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")