AgentIdentity is the primary entity in KavachOS. It represents a single AI agent, a process acting on behalf of a human user.Agents are not users. No passwords, sessions, or OAuth flows. Just tokens and permissions.
Acts independently without requiring human approval on each call, unless a permission constraint mandates it. The standard type for background agents, cron jobs, and AI assistants that run unattended.
delegated
Receives permissions from another agent via a delegation chain rather than having them declared at creation. Use this for ephemeral sub-agents spun up to complete a specific task, then discarded.
service
Long-lived identity for infrastructure, such as an MCP server or an internal microservice that calls other services on behalf of users. Treat it like a service account.
const agent = await kavach.agent.create({ ownerId: 'user-123', // ID from your auth provider name: 'github-reader', type: 'autonomous', permissions: [ { resource: 'mcp:github:*', actions: ['read'] }, ], expiresAt: new Date(Date.now() + 7 * 24 * 3_600_000), // optional metadata: { purpose: 'nightly PR review' },});console.log(agent.token); // kv_a3f8c2e1... — only shown here
The token is returned once at creation. KavachOS stores only the SHA-256 hash, so the plaintext cannot be recovered later. Save it immediately or rotate to get a new one.
Tokens use the kv_ prefix followed by 32 cryptographically random bytes encoded as 64 hex characters:
kv_a3f8c2e1d4b5... (64 hex chars after the prefix)
Authenticate by passing the token as a Bearer credential:
Authorization: Bearer kv_a3f8c2e1d4b5...
The hash-only storage model means a full database dump cannot reveal active tokens. There are no secrets to rotate after a DB breach, only the tokens themselves.
// All agents owned by a userconst agents = await kavach.agent.list({ userId: 'user-123' });// Only active autonomous agentsconst active = await kavach.agent.list({ userId: 'user-123', status: 'active', type: 'autonomous',});
await kavach.agent.revoke(agentId);// All future authorize() or authorizeByToken() calls return allowed: false// The agent's token is also invalidated immediately
Revocation is permanent. There is no un-revoke. To restore access, create a new agent.