@agenticprimitives/tool-policy

中文文档
1.0.0-alpha.46发布于 2026/10/26MITTypeScriptES Module近 30 天下载 5600

Protocol-agnostic classification, risk tiers, and exact-call policy. Consumable by MCP, A2A, LangGraph, and Vercel AI tool runtimes.

原始使用文档
文档目录5 节
  1. Quick start
  2. Exact-call policy
  3. How it's different
  4. Validate
  5. Status

@agenticprimitives/tool-policy

Part of Agentic Primitives — the open-source trust substrate for agentic applications: identity that can sign, authority checked at act time, evidence the owner carries. Developer kit · All packages

One delegation model, everywhere — and this is the layer that decides.

Agents are getting tool access faster than anyone is deciding what those tools should be allowed to do. The usual answer is an OAuth scope string or an API key with a prayer attached — coarse, transport-bound, and silent about risk. This package is the missing decision layer: a classification taxonomy (@sa-tool, @sa-auth, @sa-validation, @sa-risk-tier and friends), risk tiers with TTL clamps and required-caveat lookups, an exact-call DSL for byte-precise on-chain calls, and a deterministic decision engine — evaluatePolicy(ctx) returns allow, deny, or requires-consent, the same answer for the same input, every time. Unknown classification fields fail closed.

It is deliberately transport-free: no MCP SDK, no LangChain, no Vercel AI imports (ADR-0003). A LangGraph user can pnpm add it without buying into MCP middleware, and @agenticprimitives/mcp-runtime consumes it without being the only consumer. This package decides; your runtime enforces.

Part of agenticprimitives — the trust substrate for the agent economy: one canonical Smart Agent identity with custody, delegation, naming, credentials, and audit evidence designed as one system.

See spec.md → specs/204-tool-policy.md.

Quick start

import { declareTool, evaluatePolicy } from '@agenticprimitives/tool-policy';

const getProfileTool = declareTool(
  { name: 'get_profile', inputSchema: { /* ... */ }, handler: /* ... */ },
  {
    '@sa-tool': 'delegation-verified',
    '@sa-auth': 'session-token',
    '@sa-validation': 'shape-check',
    '@sa-risk-tier': 'low',
  },
);

const decision = evaluatePolicy({
  toolName: 'get_profile',
  classification: getProfileTool._classification,
  delegation,             // from @agenticprimitives/delegation
  callerKind: 'user-session',
});

if (decision.decision === 'deny') throw new Error(decision.reason);
if (decision.decision === 'requires-consent') /* prompt user */;

Exact-call policy

When "roughly this kind of call" is not good enough, pin the exact one:

import { exactCall, matchesExactCall } from '@agenticprimitives/tool-policy';

const policy = exactCall(safeAddress, '0xa9059cbb', {
  calldataHash: '0xdeadbeef...',
  valueLimit: 0n,
});

const ok = matchesExactCall({ to, data, value }, policy);

When calldataHash is set, matching is byte-identical — no partial-match shortcuts.

How it's different

OAuth scopes and general-purpose policy engines (OPA-style) are the incumbents here, and both have a gap this package targets. Scopes are static strings granted at consent time; they know nothing about risk tiers, value limits, or the delegation a caller actually holds. Policy engines are powerful but generic — you bring your own identity model, your own risk taxonomy, and your own integration glue per transport. This package ships the agent-tooling-specific layer pre-built: a risk taxonomy designed for tool calls, decisions that compose with Delegation objects from @agenticprimitives/delegation (consumed type-only — no runtime coupling), and a deterministic, side-effect-free engine you can golden-test. The decision an MCP server enforces is the same decision a LangGraph or A2A runtime would get, because the policy layer never learned what transport it lives in.

Validate

pnpm --filter @agenticprimitives/tool-policy typecheck
pnpm --filter @agenticprimitives/tool-policy test

Status

Alpha track — testnet-only. Spec + API stable; do not deploy to production until the gates listed in the root README.md Status section are cleared — including third-party contract audit and governance key rotation. Track every security finding live in docs/audits/findings.yaml.

版本与发布记录

@agenticprimitives/tool-policy 共发布 45 个版本,首次发布于 2026/06/01;过去 12 个月发布了 45 个版本。

版本发布日期距今
1.0.0-alpha.46latest2026/10/2610 天前
1.0.0-alpha.452026/10/2610 天前
1.0.0-alpha.442026/10/1720 天前
1.0.0-alpha.432026/10/1720 天前
1.0.0-alpha.422026/10/1620 天前
1.0.0-alpha.412026/10/1620 天前

其他发布通道:alpha → 0.1.0-alpha.2。

关于 @agenticprimitives/tool-policy 的常见问题

@agenticprimitives/tool-policy 是什么?

Protocol-agnostic classification, risk tiers, and exact-call policy. Consumable by MCP, A2A, LangGraph, and Vercel AI tool runtimes.

如何安装 @agenticprimitives/tool-policy?

在项目目录运行 npm install @agenticprimitives/tool-policy,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@agenticprimitives/types(^1.0.0-alpha.46)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@agenticprimitives/tool-policy 支持 TypeScript 吗?

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

@agenticprimitives/tool-policy 支持 ESM 还是 CommonJS?

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

@agenticprimitives/tool-policy 可以商用吗?

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

@agenticprimitives/tool-policy 的下载量有多少?

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

@agenticprimitives/tool-policy 还在维护吗?

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