Rethinking Authentication for the Agentic Era: A Deep Dive into KavachOS

The way we think about authentication is due for a fundamental rethink. For the past two decades, the authentication landscape has been built around a single assumption: a human being sits on the other end of the connection, clicking buttons in a browser. Session cookies, OAuth authorization codes, PKCE flows—all of these mechanisms were designed with human-driven workflows in mind. But the agentic era is rewriting those assumptions at speed, and the tools we rely on today were never built for what is coming.
The Human-Agent Auth Gap
When a human user authenticates to a web application, the flow is predictable. The user enters credentials, receives a session cookie valid for hours or days, and the server associates that cookie with a specific human identity. Browser sessions are persistent, tied to an origin domain, and designed for intermittent human interaction. This model works reasonably well for its intended purpose.
AI agents break every single one of those assumptions. An AI agent may spawn dozens of sub-agents, each performing specialized tasks—code review, data retrieval, document synthesis—often running concurrently and autonomously. These agents need to authenticate to multiple services within seconds, hold credentials only as long as the task requires, and operate without any human in the loop to approve each individual action. A session cookie that expires in 24 hours is far too long for an agent that needs a credential for 90 seconds. An OAuth flow that requires a human to click an authorization button is completely incompatible with autonomous operation.
The problem is not merely one of duration. It is one of granularity, trust boundaries, and the entire conceptual model of identity. Traditional authentication has two tiers: authenticated user or unauthenticated requester. Agents need something far richer—fine-grained, temporary, scoped credentials that can be issued and revoked at runtime, with full audit trails of every action taken under every delegated identity.
This is the problem space that KavachOS occupies.
KavachOS: Core Concepts
KavachOS describes itself as the first authentication framework built from the ground up for autonomous AI agents. The name “Kavach”—Sanskrit for armor or shield—reflects its design philosophy: protect the system not by keeping agents out, but by giving them precisely scoped, accountable identities that can be audited and revoked at any time.
Agent Identity
The foundational unit in KavachOS is the Agent Identity, which is fundamentally different from a user account or a browser session. An Agent Identity is a cryptographically signed identity bound to a specific autonomous system, identified by a public key, and carrying metadata that describes its capabilities, origin, and trust level. Unlike a session cookie tied to a human browser, an Agent Identity is a first-class principal in the authorization system—meaning it can be granted permissions, have those permissions revoked, and be audited independently of any human user account.
Each Agent Identity in KavachOS is associated with a manifest that declares its purpose, version, and the scopes it is authorized to request. This manifest is signed by the identity’s private key and verified by the receiving service. The result is an authentication primitive that is stateless, portable across edge deployments, and immune to session fixation attacks that plague cookie-based auth.
Delegation Chains
The most architecturally significant feature of KavachOS is its support for Delegation Chains. In a multi-agent system, an orchestrator agent frequently needs to spawn specialized sub-agents and grant them a subset of its own permissions—just enough to accomplish the task, and no more. KavachOS formalizes this pattern with a delegation mechanism that is auditable, TTL-constrained, and composable.
When an orchestrator agent delegates permissions to a sub-agent, it creates a Delegation Token. This token specifies three critical pieces of information: the exact scopes being granted, a TTL (Time To Live) measured in seconds or minutes rather than hours, and a reference to the parent identity chain. The sub-agent cannot expand its permissions beyond what the token specifies. When the TTL expires, the token becomes invalid automatically—no revocation message needs to be sent, no server-side state needs to be checked.
This design has profound security implications. Even if a sub-agent is compromised, the blast radius is limited to the narrow window and scope defined by its delegation token. The orchestrator does not need to maintain a denylist or send revocation signals. Trust is encoded in the token itself, verified cryptographically at every invocation.
Audit Trail
KavachOS implements a granular Audit Trail that records every agent action with a structured tuple: Agent Identity, Action performed, Result of the action, and Timestamp. This is not a log file with freeform strings—it is a structured, queryable audit record designed for compliance and forensic analysis.
Each audit entry in KavachOS is written to an immutable append-only log (implemented on top of SQLite, D1, or PostgreSQL depending on deployment) and carries a cryptographic hash of the previous entry, forming a chain that can detect any tampering with historical records. For organizations operating in regulated industries—financial services, healthcare, government—this audit trail is not optional. KavachOS makes it a first-class citizen of the authentication system rather than an afterthought bolted on via middleware.
Technical Implementation
MCP OAuth 2.1 and RFC 9728
KavachOS implements MCP (Model Context Protocol) OAuth 2.1, incorporating PKCE (Proof Key for Code Exchange) and RFC 9728 compatibility. For agents interacting with external services that speak standard OAuth, KavachOS acts as an intermediary that translates between its native delegation model and the OAuth 2.1 grant flow. PKCE is enforced for all flows, eliminating the risk of authorization code interception. The RFC 9728 specification for token introspection and revocation endpoints is implemented natively, meaning KavachOS-issued tokens can be introspected by any RFC-9728-compliant resource server.
Edge Runtime Compatibility
A significant practical advantage of KavachOS is its runtime compatibility. The framework compiles to a zero-dependency module compatible with Cloudflare Workers and Deno Deploy, both of which are increasingly popular for running AI agent logic at the edge. This is not a trivial engineering achievement—Cloudflare Workers execute in a V8 isolate with no filesystem and strict memory limits, while Deno Deploy runs in a sandboxed environment. KavachOS accommodates both by design, using only Web Crypto API primitives and making no assumptions about filesystem access or long-lived server-side state.
Database Compatibility
KavachOS ships with adapter layers for SQLite (via better-sqlite3), Cloudflare D1, and PostgreSQL (via the pg driver). The audit trail and delegation token store are abstracted behind a repository interface, meaning organizations can start with a local SQLite database for development and migrate to PostgreSQL in production without changing any application code. This flexibility lowers the barrier to experimentation while providing a clear upgrade path for production workloads.
TypeScript Implementation
The framework is implemented in TypeScript, with a developer-facing API that feels idiomatic to the modern AI engineering stack. Below are two code examples illustrating the core primitives.
The createKavach function initializes a new Agent Identity. It generates an asymmetric key pair using the Web Crypto API, creates a signed identity manifest, and registers the identity with the local KavachOS instance. The private key never leaves the agent’s secure enclave; only the public key and signed manifest are stored externally.
import { createKavach, delegate } from "@kavachos/core";
import type { AgentIdentity, DelegationOptions } from "@kavachos/core";
// Initialize a new Agent Identity for an orchestrator agent
const orchestrator = await createKavach({
name: "orchestrator-primary",
version: "1.0.0",
capabilities: ["read", "write", "delegate"],
ttl: 3600, // 1 hour base TTL for the orchestrator's own identity
metadata: {
owner: "team-ai-platform",
environment: "production",
},
});
console.log("Orchestrator Identity created:");
console.log(` Public Key ID: ${orchestrator.publicKeyId}`);
console.log(` Capabilities: ${orchestrator.capabilities.join(", ")}`);
The delegate function creates a scoped, time-limited delegation token for a sub-agent. In the example below, the orchestrator delegates a read-only permission set to a Code-Reviewer Agent with a TTL of 120 seconds—just long enough for a single code review task to complete.
import { delegate } from "@kavachos/core";
import type { DelegationOptions } from "@kavachos/core";
// Orchestrator delegates read-only access to a Code-Reviewer sub-agent
const delegationOptions: DelegationOptions = {
parentIdentity: orchestrator,
targetAgent: {
name: "code-reviewer-v2",
publicKeyId: "pk_code_reviewer_v2_fingerprint",
},
scopes: ["repository:read", "pullrequest:read", "comment:read"],
ttl: 120, // 2 minutes - task-specific, not session-based
constraints: {
allowNetwork: ["github.com", "gitlab.internal"],
maxFileSize: "5MB",
auditRequired: true,
},
};
const codeReviewerToken = await delegate(delegationOptions);
console.log("Delegation Token issued:");
console.log(` Token ID: ${codeReviewerToken.id}`);
console.log(` Scopes: ${codeReviewerToken.scopes.join(", ")}`);
console.log(` Expires in: ${codeReviewerToken.ttl}s`);
console.log(` Chain: ${codeReviewerToken.parentChain}`);
KavachOS vs. The Field: How It Compares
To appreciate what KavachOS brings to the table, it helps to examine how it stacks up against established authentication frameworks that developers might consider for agentic workloads.
Better Auth is a well-regarded open-source authentication library for TypeScript applications, with solid support for email/password, OAuth providers, and WebAuthn. It is developer-friendly, actively maintained, and works well for human-centric auth. However, Better Auth has no concept of agent delegation chains, no native TTL enforcement at the token level, and no audit trail structured for agent action tracking. Using Better Auth for an AI agent system means building all of that machinery yourself on top of its primitives—and the resulting solution will be an awkward hybrid that fights the framework’s assumptions rather than working with them.
Keycloak is the enterprise-grade standard for identity and access management. It supports OAuth 2.0, SAML, LDAP, and a rich policy engine. Keycloak is battle-tested in Fortune 500 environments and can technically be extended to handle machine-to-machine authentication. But Keycloak was designed for organizational identity federations, not autonomous agent systems. Its weight—requiring a JVM, a relational database, and a non-trivial configuration surface—makes it poorly suited for edge deployments. The delegation model in Keycloak relies on authorization scopes attached to OAuth clients, not on the fine-grained, time-limited, chain-verifiable tokens that agents need. Running Keycloak as the auth back-end for a fleet of ephemeral AI agents is technically possible, but it is like using a cargo ship to deliver a pizza.
Supabase Auth brings a developer-friendly, Postgres-native auth system that handles email/password, OAuth, and magic links. For applications where a human user triggers server-side logic, Supabase Auth is excellent. Its Row Level Security integration is particularly clever, tying auth directly to database access policies. For AI agents, however, Supabase Auth’s design assumptions become limitations. Authentication is user-centric, tokens are session-based with minimum TTLs that are too long for agent use cases, and there is no delegation primitive whatsoever. The best Supabase Auth can offer an agent system is a long-lived service role key—which is precisely the blast-radius problem that KavachOS was designed to eliminate.
Case Study: Orchestrator Delegating Read-Only Access to a Code-Reviewer Agent
Consider a production scenario: a software engineering platform runs an Orchestrator Agent responsible for managing the codebase. A developer requests a code review for Pull Request #847. The Orchestrator spawns a Code-Reviewer Agent to perform the analysis.
In the KavachOS implementation of this workflow, the Orchestrator first authenticates using its own Agent Identity, verified against the platform’s KavachOS instance. It then calls delegate() to issue a scoped token to the Code-Reviewer Agent. The token’s scopes are restricted to repository:read and pullrequest:read—no write, no delete, no admin. The TTL is set to 180 seconds. The token also carries a network constraint: the Code-Reviewer Agent can only reach the internal Git host and the code review service.
When the Code-Reviewer Agent attempts to read the pull request diff, its token is verified by the Git host’s KavachOS middleware. The token’s signature, TTL, and scope are checked in a single synchronous call—taking typically under 5 milliseconds on a Cloudflare Worker. The Git host returns the diff. The Code-Reviewer Agent performs its analysis and posts a comment back to the pull request, but it does so using a separate write token that the Orchestrator issued with even tighter constraints: comment:write only, 60-second TTL, restricted to the specific PR thread.
Every action—diff read, comment posted, any network attempt blocked by constraint—is recorded in the immutable audit trail with full identity chaining. If the Code-Reviewer Agent’s token is somehow exfiltrated, it is useless after 180 seconds and is limited to read operations only. The blast radius of a compromise is measured in minutes and read operations, not hours and full account access.
Conclusion
KavachOS is not attempting to replace OAuth or LDAP or any of the foundational identity protocols that the internet runs on. What it is doing—and doing with careful engineering precision—is filling the gap that those protocols were never designed to cover: the identity, authorization, and audit needs of autonomous software agents operating at machine speed and machine scale. This granular control is essential when deploying agents in environments where AI-induced productivity regressions are a concern, requiring rigorous auditability to maintain system integrity.
The authentication landscape built for human users served us well for two decades. As AI agents become first-class actors in our software ecosystems, the frameworks that govern their identities will determine whether the agentic era is a secure one or a chaotic one. KavachOS represents a serious, technically rigorous attempt to make it the former.
Explore the project on GitHub, read the Model Context Protocol (MCP) documentation, and join the growing community of engineers building agent-native infrastructure. For more on optimizing agent performance at the data layer, see our recent analysis of TurboQuant and LLM KV cache compression.
Discover more from Susiloharjo
Subscribe to get the latest posts sent to your email.