@absolutejs/agency

中文文档
0.7.4发布于 2026/08/01MITTypeScriptES Module近 30 天下载 2269

Provider-agnostic AI agent authorization with policy, approvals, rejections, durable delegation, execution leases, receipts, kill switches, and signed handoffs.

原始使用文档
文档目录4 节
  1. Agentic control plane
  2. Handoffs, simulation, and telemetry
  3. PostgreSQL production state
  4. License

@absolutejs/agency

Provider-neutral action authorization for AI agents.

Authentication says which agent is acting and on whose behalf. Agency decides whether that exact action may happen now, coordinates prerequisites such as human approval or terminal human rejection, issues a short-lived single-use execution lease, and records a receipt after execution.

import { createAgency, createMemoryAgencyStore } from "@absolutejs/agency";

const agency = createAgency({
  policy: yourPolicyDecisionPoint,
  store: createMemoryAgencyStore(),
});

const { action, decision } = await agency.request({
  action: "send_email",
  actor: {
    agentId: "sales-agent",
    delegationId: "delegation-123",
    scopes: ["email:send"],
    userId: "user-123",
  },
  effects: ["send", "external-network"],
  input: { subject: "Hello", to: "[email protected]" },
  resource: { id: "[email protected]", type: "email_recipient" },
});

if (decision.kind === "allow") {
  const lease = await agency.issueLease(action.actionId);
  const { receipt } = await agency.execute({
    executor: "email-provider",
    leaseId: lease.leaseId,
    run: () => email.send(action.input),
  });
}

if (decision.kind === "deny" && decision.requestable) {
  await agency.reject({
    actionId: action.actionId,
    reason: "The recipient is outside the approved customer account.",
    rejectedBy: "operator-123",
  });
}

The core contract is deliberately provider-neutral. @absolutejs/agency/authzen contains adapters for the OpenID AuthZEN Authorization API, its Access Request and Approval Profile (AARP), and MCP tool mappings compatible with the COAZ profile direction.

Agentic control plane

createAgentControlPlane() inventories an agent's registrations, delegations, tasks, credential grants, allowances, mandates, leases, and other capabilities through small AgentControlSource adapters. Revocation activates a durable kill switch first, then fans out cleanup to every source. Pass the control plane to createAgency({ control, ... }); action requests, lease issuance, and execution then fail closed while the agent is disabled.

Handoffs, simulation, and telemetry

createAgentDelegationAuthority() issues durable, revocable delegation grants inside Agency. Every child must attenuate its parent's user, audience, expiry, action scopes, effects, resource boundaries, and spend ceiling; delegation depth is bounded and revocation cascades to descendants. Pass the authority as createAgency({ delegations: authority, ... }) to re-check the complete active chain when an action is requested, when its execution lease is issued, and immediately before that lease is consumed.

const delegations = createAgentDelegationAuthority({
  audience: "https://app.example",
  store: createMemoryAgentDelegationStore(), // use PostgreSQL in production
});

const grant = await delegations.issue({
  audience: "https://app.example",
  issuerAgentId: "user-agent",
  subjectAgentId: "calendar-agent",
  userId: "user-1",
  scopes: ["calendar.create"],
  effects: ["write", "external-network"],
  resourceTypes: ["calendar"],
  expiresAt: Date.now() + 3_600_000,
});
  • signAgentHandoff() / verifyAgentHandoff() create audience-bound, expiring, replay-protected agent-to-agent capability envelopes. Use attenuateAgentHandoff() for additional hops so scopes, spend, expiry, and user identity cannot escalate.
  • signAgentHandoffWith() / verifyAgentHandoffWith() accept independent signer and verifier providers over canonical bytes. Cloud KMS/HSM adapters can keep private keys non-exportable, rotate by keyId, and reject algorithms without changing the handoff wire contract. HS256 remains available for compatibility and local development.
  • simulateAction() evaluates policy and produces the same canonical binding without storing an action, issuing a lease, or running an effect.
  • createAgencyTelemetryEmitter() maps every Agency event to stable agent.* event names and attributes that can feed OpenTelemetry or any audit sink without coupling the core package to a telemetry vendor.

Memory stores are development defaults. Production deployments should supply durable, transactional stores for Agency state, kill switches, and handoff nonces.

PostgreSQL production state

agencyPostgresSchemaSql() creates indexed tables for actions, approvals, rejections, leases, receipts, kill switches, and replay nonces. The adapters accept a small structural AgencySqlClient, so Bun SQL, Neon, pg, and transaction-aware host clients can be used without coupling the core package to a database driver.

const store = createPostgresAgencyStore({ client: sqlClient });
const controlStore = createPostgresAgentControlStore({ client: sqlClient });
const replayStore = createPostgresHandoffReplayStore({ client: sqlClient });

Lease consumption is one conditional UPDATE, making concurrent execution attempts safe across processes. Handoff nonces are persisted as SHA-256 digests, not bearer values. Apply agencyPostgresSchemaSql() during deployment before starting workers.

Security invariants:

  • Approval and rejection are bound to the canonical action, actor, resource, effects, input digest, spend, and expiry.
  • Approval-versus-rejection decisions are first-writer-wins, including across PostgreSQL processes; a later concurrent decision cannot replace the original operator decision.
  • A rejected action can never receive an execution lease.
  • Policy is re-evaluated after approval and immediately before issuing a lease.
  • Execution leases are short-lived and single-use.
  • A consumed lease remains consumed when provider execution fails.
  • Successful and failed executions produce receipts.
  • The default policy helper is deny-all; permissive policy is explicit.

License

MIT

版本与发布记录

@absolutejs/agency 共发布 16 个版本,首次发布于 2026/07/16;过去 12 个月发布了 16 个版本。

版本发布日期距今
0.7.4latest2026/08/013 个月前
0.7.32026/07/253 个月前
0.7.22026/07/253 个月前
0.7.12026/07/243 个月前
0.7.02026/07/243 个月前
0.6.42026/07/233 个月前

关于 @absolutejs/agency 的常见问题

@absolutejs/agency 是什么?

Provider-agnostic AI agent authorization with policy, approvals, rejections, durable delegation, execution leases, receipts, kill switches, and signed handoffs.

如何安装 @absolutejs/agency?

在项目目录运行 npm install @absolutejs/agency,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:drizzle-orm(>=1.0.0-rc.4 <2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@absolutejs/agency 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@absolutejs/agency 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@absolutejs/agency 可以商用吗?

@absolutejs/agency 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@absolutejs/agency 的下载量有多少?

根据 npm 官方下载统计,@absolutejs/agency 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,269 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@absolutejs/agency 还在维护吗?

最新版本 0.7.4 发布于 2026/08/01(3 个月前);至今共发布 16 个版本,其中过去 12 个月发布了 16 个;首次发布于 2026/07/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。