Every agent is a principal in your IAM model. Not a service account someone shares across workflows. Not the user's session token passed through. A scoped, attested, revocable identity per agent role, issued per invocation. You already know how to answer the hard questions for humans and services. Apply the same model here: who can spawn agents, what scopes they can inherit, whether scopes are revoked when the user offboards.
// Bad: every agent shares one identity. One compromise, all agents.
const agent = createAgent({ apiKey: process.env.SERVICE_API_KEY })
// Good: scoped, time-bound, bound to this exact invocation.
const token = await iam.issue({
principal: 'agent:email-drafter',
scopes: [
'gmail:threads:read',
'gmail:drafts:create',
],
ttl: '15m',
claims: { userId, sessionId, taskId }, // bound to this task
})
const agent = createAgent({ token })
// Expires in 15 min. Scoped to one user, one session, one task.
// Revoke the token and the agent goes dark.
// User offboards: their agent tokens go with them.
Treat your agent like an intern with root. Onboard it. Scope it. Audit it. Offboard it.