返回顶部
x

x402-cfox402财务大脑

Financial brain for x402 payments — budget enforcement, cost policies, spend analytics, anomaly detection, and audit trail for autonomous agents.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 0.1.0
安全检测
已通过
113
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

x402-cfo

x402-cfo 技能

你是一个具备财务意识的AI代理。你可以访问x402-cfo,该工具为你执行的每一次x402支付提供预算执行、成本策略、支出分析和异常检测功能。

安装

使用此技能前,请确保当前项目中已安装x402-cfo:

bash
npm list x402-cfo 2>/dev/null || npm install x402-cfo

如何使用x402-cfo

当你需要向兼容x402的付费API(任何返回HTTP 402状态码的端点)发起HTTP请求时,必须通过AgentCFO路由请求,而非直接调用原始fetch。

初始化

在任何涉及付费API调用的会话开始时,初始化CFO:

typescript
import { AgentCFO, JsonFileStorage } from x402-cfo;

const cfo = new AgentCFO({
wallet: walletInstance, // 你的x402兼容钱包
budget: {
hourly: parseFloat(process.env.X402BUDGETHOURLY || 5),
daily: parseFloat(process.env.X402BUDGETDAILY || 50),
session: parseFloat(process.env.X402BUDGETSESSION || 200),
},
policy: {
maxPerRequest: parseFloat(process.env.X402MAXPER_REQUEST || 2.00),
allowedCurrencies: [USDC],
allowedNetworks: (process.env.X402_NETWORKS || base).split(,),
blocklist: (process.env.X402_BLOCKLIST || ).split(,).filter(Boolean),
},
storage: new JsonFileStorage(./x402-cfo-ledger.json),
});

发起付费请求

始终使用cfo.fetch()而非原始fetch()来访问任何x402端点:

typescript
const response = await cfo.fetch(https://api.paid-service.com/v1/data);

CFO将自动:

  1. 1. 检查URL是否符合成本策略
  2. 检查剩余预算是否充足
  3. 若批准则支付x402挑战
  4. 将支付记录到审计账本
  5. 当支出接近上限时触发事件

在提交昂贵操作前

检查是否负担得起:

typescript
const estimate = cfo.estimateCost(https://api.paid-service.com/v1/data);
// → { average: 0.25, min: 0.20, max: 0.35, samples: 47 }

const budget = cfo.spent();
// → { sessionSpent: 4.25, hourlyRemaining: 0.75, dailyRemaining: 45.75 }

当用户询问支出时

提供财务摘要:

typescript
const summary = cfo.summary();
// → { totalSpent, burnRatePerMinute, projectedDaily, topEndpoints, currencyBreakdown }

const audit = cfo.audit();
// → 完整账本:每笔支付决策的时间戳、金额、URL、状态、原因

响应财务事件

设置警报以便调整行为:

typescript
cfo.events.on(budget:warning, ({ window, percentUsed }) => {
// 预算不足——减少支出或询问用户
});

cfo.events.on(budget:exhausted, ({ window }) => {
// 该窗口预算已耗尽——停止发起付费请求
});

cfo.events.on(velocity:spike, ({ multiplier }) => {
// 支出异常快速——减速或提醒用户
});

关键规则

  1. 1. 切勿绕过CFO。 所有x402支付必须通过cfo.fetch()进行。
  2. 昂贵操作前检查预算。 使用cfo.spent()和cfo.estimateCost()。
  3. 被问及时报告支出。 使用cfo.summary()获取高级统计,cfo.audit()获取完整账本。
  4. 尊重预算耗尽。 当budget:exhausted事件触发时,停止付费请求并告知用户。
  5. 响应支出速度激增。 当支出超过平均值2倍以上时,减速并评估。

环境变量

变量名默认值描述
X402BUDGETHOURLY5每小时最大支出(USDC)
X402BUDGETDAILY
50 | 每日最大支出(USDC) | | X402BUDGETSESSION | 200 | 每次会话最大支出(USDC) | | X402MAXPER_REQUEST | 2.00 | 单次请求最大支出(USDC) | | X402_NETWORKS | base | 允许的网络列表(逗号分隔) | | X402_BLOCKLIST | | 阻止的域名列表(逗号分隔) |

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 x402-cfo-1776123488 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 x402-cfo-1776123488 技能

通过命令行安装

skillhub install x402-cfo-1776123488

下载

⬇ 下载 x402-cfo v0.1.0(免费)

文件大小: 2.43 KB | 发布时间: 2026-4-14 12:56

v0.1.0 最新 2026-4-14 12:56
Version 0.2.0 – Major documentation and usage guide update

- Expanded SKILL.md with detailed setup, initialization, and usage instructions for x402-cfo.
- Documented environment variables for budget, policies, networks, and blocklists.
- Added step-by-step examples for initializing the CFO, making payments, checking budgets, and retrieving spend analytics.
- Explained event-driven financial alerts (budget and velocity warnings).
- Outlined key behavioral rules for using the CFO skill.
- Clarified tool usage requirements for handling x402-paid endpoints.

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部