Cost Guardian:优化 AI Token 支出与 Cron 工作流 - Openclaw Skills

作者:互联网

2026-04-18

AI教程

什么是 Cost Guardian?

Cost Guardian 充当您自动化代理工作流的财务审计员。它专门设计用于识别和标记昂贵的运营模式,例如高频轮询或为简单的状态检查使用高级 LLM 模型。通过将此逻辑集成到您的 Openclaw Skills 库中,您可以确保每项自动化任务在上线前都经过了成本优化。

该技能为您 AI 基础设施的财务影响提供了关键的可见性。它以建议的方式运行,这意味着它永远不会修改您的文件或执行命令,而是提供必要的数据驱动洞察,以便开发人员能够针对其 Token 预算和资源分配做出明智的决策。

下载入口:https://github.com/openclaw/skills/tree/main/skills/vnakhate/openclaw-cost-guardian

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install openclaw-cost-guardian

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 openclaw-cost-guardian。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

Cost Guardian 应用场景

  • 防止高频 cron 任务检查新数据时产生的过度账单。
  • 优化 Antfarm 工作流轮询间隔以减少不必要的 API 调用。
  • 为心跳和监控任务选择更具成本效益的 Flash 级别模型。
  • 为新的 AI 驱动自动化程序生成月度成本预测。
  • 审计现有的 Openclaw Skills 配置以发现即时节省空间。
Cost Guardian 工作原理
  1. 每当用户提出新的 cron 任务、工作流或询问运营成本时,该技能就会被触发。
  2. 它会分析任务类别(例如每日报告与实时监控)以确定理想的轮询间隔。
  3. 它会审查选定的 LLM,并建议在处理简单的“查看”任务时切换到更便宜的模型。
  4. 它会根据当前的 Token 费率计算详细的成本预测,包括每日调用次数和预计月度支出。
  5. 用户将收到关于如何调整设置的清晰建议,以便在保持功能的同时最大限度地减少支出。

Cost Guardian 配置指南

Cost Guardian 是标准 Openclaw Skills 仓库的一部分。要验证其存在并开始将其用于成本审计,请使用以下命令:

# 列出可用技能以确保 cost-guardian 已激活
openclaw skills list

# 在规划新工作流时调用 Guardian
openclaw run cost-guardian "查看我的电子邮件轮询 cron 任务"

Cost Guardian 数据架构与分类体系

该技能通过一组结构化的规则和阈值来组织其审计逻辑。它使用以下分类展示数据:

组件 描述
任务类型 将工作分类为每日、监控或心跳,以设定间隔基准。
推荐模型 将任务复杂度映射到最经济的模型(例如,心跳使用 Flash 级别模型)。
成本估算 提供透明的数学计算:(间隔) x (Token) x (模型费率) = 月度总计。
警报级别 使用定义的预算阈值(例如每月 5 美元限额)触发警告。
name: cost-guardian
description: "Prevents wasteful token spend. Reviews cron jobs, polling intervals, and model selection before they go live. Recommends cost-saving changes and flags expensive patterns. Invoke when creating cron jobs, workflows, or when asked about costs/usage."
user-invocable: true

Cost Guardian

Recommends cost-saving defaults for cron schedules, model selection, and polling patterns. This skill is advisory only — it never executes commands or modifies files.

Scope

This skill only provides recommendations. It will:

  • Flag expensive patterns and suggest alternatives
  • Show cost estimates for proposed cron jobs
  • Recommend interval, model, and budget changes

It will not:

  • Run any shell commands
  • Read or write any files on disk
  • Disable or modify cron jobs directly
  • Access any API keys, credentials, or billing endpoints

All actions are the user's responsibility.

Rules — ALWAYS apply these when reviewing

1. Cron Polling Intervals

Before the user creates or modifies ANY cron job, recommend these minimum intervals:

Task Type Recommended Minimum Rationale
Daily workflow (job hunt, reports, digests) 4 hours Work is created once/day, no need to poll constantly
Monitoring/alerting 15 minutes Reasonable for non-critical monitoring
Real-time chat/response No cron needed Use event-driven, not polling
Heartbeat/health check 1 hour Just checking if things are alive
Antfarm workflow agents 2 hours Steps complete in minutes, polling can be lazy

Flag any polling interval under 5 minutes as expensive. Show the cost estimate and let the user decide.

2. Model Selection for Cron Jobs

Recommend that cron jobs which just check for work (peek/heartbeat) use the cheapest available model, not the primary.

Task Recommended Model
Heartbeat / peek for work Cheapest available (e.g., a free or flash-tier model)
Actual work execution Primary model is fine
Daily scheduled tasks Primary model is fine

Flag expensive models used for heartbeat polling. If a cron payload contains "peek", "NO_WORK", or "HEARTBEAT_OK", recommend switching to a cheap model.

3. Cost Estimation — Show Before Creating

Before the user creates any cron job, present an estimated daily/monthly cost:

Estimated cost:
  Calls/day: {24 * 60 / interval_minutes}
  ~tokens/call: {estimate based on payload size}
  Model rate: {input + output per M tokens}
  Daily cost: ${calls * tokens * rate}
  Monthly cost: ${daily * 30}

Recommend user confirmation if the monthly estimate exceeds $5.

4. Budget Alerts

Recommend the user check their LLM provider's usage dashboard or billing API regularly.

Suggested alert thresholds:

  • Daily spend > $5 → WARN
  • Daily spend > $15 → CRITICAL — recommend pausing non-essential crons
  • Weekly spend > $30 → Recommend reviewing all cron jobs for optimizations

5. Antfarm Workflow Guard

When the user sets up antfarm workflows, recommend:

  • Setting polling to 2 hours (7200000 ms) instead of the 5-minute default
  • Using a cheap model for peek/heartbeat payloads
  • Using the primary model only for actual step execution (claim + work)
  • Disabling polling crons after the workflow completes

6. Audit Checklist

When the user asks to audit costs, suggest they:

  1. Check provider spend via their billing dashboard
  2. List all active cron jobs
  3. Flag any job polling more frequently than its category minimum
  4. Flag any heartbeat job using an expensive model
  5. Calculate projected monthly cost
  6. Apply recommended changes

Example Intervention

User says: "Set up a cron to check for new emails every minute"

Cost Guardian response:

Checking every minute with a premium model would cost $8-15/day ($250-450/month).

Recommended: Every 15 minutes with a free/flash-tier model. That's $0/day and you'll still catch emails within 15 min.

Would you like to use those settings instead?

相关推荐