在 LangChain.js 里,付款之前先检查
Agent 准备付钱之前,先问 OceanAlt:收款方是不是制裁或高风险地址,付款页面是不是仿冒的。每次检查返回三种结果之一:allow(没有发现阻断性问题)、review(先交给人确认)、decline(不要付)。检查跑不了时一律返回 review,不会变成 allow。包里不保存密钥,也不经手资金。
安装
npm install @oceanalt/langchain @langchain/core zod用法一:给模型用的检查工具(建议性)
oceanalt_check_payee 查收款方(调用 POST /api/decide),oceanalt_check_payment_endpoint 查付款网址(调用 GET /api/endpoint)。两个工具都返回 JSON 字符串。模型自己决定调不调、听不听,所以这是建议性的。
import { oceanaltTools } from "@oceanalt/langchain";
const tools = [...oceanaltTools(), ...yourTools];
const modelWithTools = model.bindTools(tools);用法二:拦在付款工具前面的守卫(强制)
guardPaymentTool 返回一个名字、说明、参数都不变的新工具。调用时先按工具的 schema 解析参数,再检查收款方:decline 抛出 OceanAltDeclinedError,原工具不执行;review 只有在 onReview 返回 true 时才执行,否则抛出 OceanAltReviewRequiredError;检查失败按 review 处理。
import { tool } from "@langchain/core/tools";
import { z } from "zod";
import { guardPaymentTool } from "@oceanalt/langchain";
const transfer = tool(async ({ recipient, amount }) => sendUsdc(recipient, amount), {
name: "transfer_usdc",
description: "Send USDC on Base",
schema: z.object({ recipient: z.string(), amount: z.number() }),
});
// decline -> OceanAltDeclinedError, the transfer does not run.
// review -> runs only if onReview returns true (after a human agreed).
const guardedTransfer = guardPaymentTool(transfer, {
getPayment: (args) => ({ to: args.recipient, amountUsdc: args.amount, network: "base" }),
onReview: async (result, args) => askAHuman(result, args),
});
// use guardedTransfer in place of transfer, e.g. createReactAgent({ llm, tools: [guardedTransfer] })返回什么
decision、verdict、reason_code、retry、advice、signal_keys、evidence,以及给模型的一句 instruction。结果是基于公开数据的筛查结论,不是安全保证。

