Use case
Auth for orchestrators that spawn sub-agents.
When one agent hands work to another, the second one should hold less than the first, for less time, and be stoppable on its own. This page shows how delegation chains do that in theAuth, with code that was run before it was published.
The problem
One shared key per swarm does not survive an incident.
A planner splits a task. A reviewer reads pull requests. A fetcher pulls diffs. If all three use the same API key, you cannot tell them apart in logs, you cannot cut one off, and the fetcher can do whatever the planner can.
The fix is the same one operating systems use for processes: each worker gets its own identity, receives a subset of its parent's rights, and loses them when the parent's grant is withdrawn.
The theAuth path
Identities, narrowing delegation, then audit.
- Identityagent.create
- Every agent has an owner, a type (
autonomous,delegatedorservice), akv_bearer token shown once, and permissions as resource patterns plus actions. - Delegationtheauth.delegate
- The parent grants a subset of its own permissions to a child, with an expiry and a
maxDepth. Wider resources or new actions are rejected at creation. - Revocationdelegation.revoke
- Revoking a link also revokes the links created downstream of it. It applies on the next
authorize()call, not to work already running. - Budgets and approvalpolicies, approval
- Budget policies cap token cost and call counts per agent. Permissions with
requireApprovalare denied until a human approves. Both are opt-in modules, covered below. - Auditaudit.query
- Each decision records agent, owner, action, resource, result and duration, exportable as JSON or CSV.
In code
A planner delegates one read-only slice to a reviewer.
Run on @glinr/theauth 0.6.0 on 2026-10-08. It prints read: true, write: false, then read after revoke: false. The reviewer is created with no permissions of its own, so everything it can do comes from the chain.
import { createTheAuth, users } from "@glinr/theauth";
const theauth = await createTheAuth({
database: { provider: "sqlite", url: ":memory:" },
agents: { enabled: true },
});
// Agents need an owner row. In a real app the owner is a signed-in user.
await theauth.db.insert(users).values({ id: "user-1", email: "[email protected]", createdAt: new Date(), updatedAt: new Date() });
const orchestrator = await theauth.agent.create({
ownerId: "user-1",
name: "planner",
type: "autonomous",
permissions: [{ resource: "mcp:github:*", actions: ["read", "write"] }],
});
const reviewer = await theauth.agent.create({
ownerId: "user-1",
name: "reviewer",
type: "delegated",
permissions: [],
});
// The planner hands the reviewer a narrower slice, for one hour, one hop deep.
const chain = await theauth.delegate({
fromAgent: orchestrator.id,
toAgent: reviewer.id,
permissions: [{ resource: "mcp:github:pulls", actions: ["read"] }],
expiresAt: new Date(Date.now() + 3_600_000),
maxDepth: 1,
});
const read = { action: "read", resource: "mcp:github:pulls" };
const write = { action: "write", resource: "mcp:github:pulls" };
console.log("read:", (await theauth.authorize(reviewer.id, read)).allowed);
console.log("write:", (await theauth.authorize(reviewer.id, write)).allowed);
await theauth.delegation.revoke(chain.id);
console.log("read after revoke:", (await theauth.authorize(reviewer.id, read)).allowed);Install with pnpm add @glinr/theauth sql.js and run with pnpm tsx multi-agent.ts. Setup details are on the get started page.
Pitfalls
Limits worth knowing before you ship.
- Budgets are not enforced by authorize.Call
policies.checkBudget()before an LLM call andrecordUsage()after it. Nothing is capped unless your code does this. - Re-delegation uses the parent's own permissions.An agent that holds only delegated permissions cannot pass them on. Give an intermediate agent its own copy if it must re-delegate.
- maxDepth is per call.It is checked on each
delegate()call and not stored as a ceiling for later hops. Pass a small value on every call. - Revocation is eventual per call.It takes effect on the next
authorize(). Operations already in flight keep running. - Approval needs your UI.theAuth stores approval requests but ships no screen and does not deliver the notification.
Keep reading
Get started
Give your first agent an identity.
Install the package, create an agent with scoped permissions, and read its first audit record. The core runs on Postgres, SQLite, MySQL or D1, and the Go module needs a single go get.
npm install @glinr/theauthgo get github.com/glincker/theauth-go/v2