Credential Vault and Auth Framework for AI Agents
raw JSON →agent.pw is a robust credential vault and authentication framework specifically designed for AI agents. It provides secure storage for encrypted credentials, including OAuth tokens and API keys, utilizing AES-GCM for data at rest. The library manages the entire OAuth lifecycle, supporting PKCE, token refresh, revocation, and RFC 9728 discovery. Currently at version 0.8.2, the project exhibits a rapid release cadence with frequent patch and minor updates (multiple in April 2026 alone), indicating active development and continuous improvement. Key differentiators include its agent-centric design, comprehensive OAuth handling, support for admin-configurable credential profiles, path-based organization (`ltree` paths like `acme.connections.github`), and scoped access control. It is designed to be embeddable, working seamlessly with any PostgreSQL-compatible database without requiring a separate server component.
Common errors
error Error: DATABASE_URL environment variable is required. ↓
DATABASE_URL environment variable in your environment (e.g., .env file, shell export) to a valid PostgreSQL connection string before running your application. error Error: AGENTPW_ENCRYPTION_KEY environment variable is required. ↓
AGENTPW_ENCRYPTION_KEY environment variable. This key is used to encrypt all stored credentials. error OAuthError: Invalid redirect_uri ↓
redirectUri parameter against your OAuth application's configuration on the provider's side and ensure they are an exact match, including protocol, hostname, port, and path. error Error: Unwrapped an Err value. Original error: [Some specific database error] ↓
DATABASE_URL, network connectivity to the database, or database permissions. Ensure your database is running and accessible. Warnings
breaking As `agent.pw` is in active `0.x.x` development, minor version increments (e.g., `0.6.0` to `0.7.0`) may introduce breaking API changes not explicitly detailed as such. Always review release notes carefully when upgrading. ↓
gotcha The `encryptionKey` is critical for credential security. Losing this key will result in irreversible loss of access to all encrypted credentials stored by `agent.pw`. It must be a strong, securely generated secret. ↓
gotcha Many `agent.pw` operations return `Result` types (an `Ok` or `Err` wrapper) requiring the use of `unwrap` from `okay-error`. Failing to handle potential errors from `unwrap` can lead to uncaught exceptions and application crashes. ↓
breaking Version `0.8.0` introduced the ability to initialize with a profile-only configuration without an encryption key, but the core `createAgentPw` function still mandates an `encryptionKey` if you intend to store secrets. This feature primarily applies to specific `connect.prepare` flows. ↓
gotcha The OAuth redirect URIs (`redirectUri`) specified in `agentPw.connect.startOAuth` must exactly match the redirect URIs configured with the OAuth provider. Mismatches will result in authorization failures. ↓
Install
npm install agent.pw yarn add agent.pw pnpm add agent.pw Imports
- createAgentPw wrong
const { createAgentPw } = require('agent.pw');correctimport { createAgentPw } from 'agent.pw'; - createInMemoryFlowStore wrong
import { createInMemoryFlowStore } from 'agent.pw';correctimport { createInMemoryFlowStore } from 'agent.pw/oauth'; - createDb wrong
import { createDb } from 'agent.pw';correctimport { createDb } from 'agent.pw/sql'; - unwrap wrong
import { unwrap } from 'agent.pw';correctimport { unwrap } from 'okay-error';
Quickstart
import { createAgentPw } from "agent.pw";
import { createInMemoryFlowStore } from "agent.pw/oauth";
import { createDb } from "agent.pw/sql";
import { unwrap } from "okay-error";
async function initializeAgentPw() {
const databaseUrl = process.env.DATABASE_URL ?? '';
if (!databaseUrl) {
throw new Error("DATABASE_URL environment variable is required.");
}
const encryptionKey = process.env.AGENTPW_ENCRYPTION_KEY ?? '';
if (!encryptionKey) {
throw new Error("AGENTPW_ENCRYPTION_KEY environment variable is required.");
}
const db = unwrap(createDb(databaseUrl));
const agentPw = await unwrap(
createAgentPw({
db,
encryptionKey,
flowStore: createInMemoryFlowStore(),
}),
);
console.log('agent.pw initialized successfully.');
// Example: Resolve headers for a previously connected resource
const path = "acme.connections.docs"; // Replace with your resource path
try {
const headers = await unwrap(agentPw.connect.resolveHeaders({ path }));
console.log(`Resolved headers for ${path}:`, headers);
} catch (error) {
console.error(`Failed to resolve headers for ${path}:`, error);
}
return agentPw;
}
initializeAgentPw().catch(console.error);