在 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。結果是基於公開數據的篩查結論,不是安全保證。

