← 返回
AI智能

OpenClaw Cost Guard (Budgets + Token-Saving Playbook)

Track OpenClaw/Clawdbot token and cost usage from session JSONL logs (prefer real usage.cost when present), generate daily/weekly summaries and top expensive sessions, and run budget checks (exit code on breach). Use to monitor spend, enforce budgets via cron/alerts, and apply a token-saving playbook to reduce output/tool-call cost.
追踪 OpenClaw/Clawdbot 的令牌和成本使用情况(优先使用 usage.cost),生成每日/每周汇总和高开销会话,并执行预算检查(违规时返回退出码)。用于监控支出、通过 cron/告警强制执行预算,以及应用令牌节省方案以降低输出和工具调用成本。
dasweltall
AI智能 clawhub v0.1.0 1 版本 99579.3 Key: 无需
★ 4
Stars
📥 3,707
下载
💾 671
安装
1
版本
#alerts#budget#clawdbot#cost#cron#latest#monitoring#openclaw#ops#optimization#telemetry#token#usage

概述

OpenClaw Cost Guard

Use this skill when you need:

  • accurate cost reports (daily/weekly/lifetime)
  • top expensive sessions
  • guardrails to reduce token burn (without changing config unless user asks)

1) Data source (important)

Prefer session JSONL logs (they contain per-call usage, often with real USD cost):

  • OpenClaw: ~/.openclaw/agents//sessions/.jsonl
  • Legacy/compat: ~/.clawdbot/agents//sessions/.jsonl

Do not estimate from “current context window” style token fields.

2) Quick commands

Daily costs (last 7 days)

python3 {baseDir}/scripts/extract_cost.py --last-days 7

Today / yesterday

python3 {baseDir}/scripts/extract_cost.py --today
python3 {baseDir}/scripts/extract_cost.py --yesterday

Top expensive sessions

python3 {baseDir}/scripts/extract_cost.py --top-sessions 10

JSON output (for dashboards)

python3 {baseDir}/scripts/extract_cost.py --last-days 30 --json

3) If cost is missing (fallback estimate)

Some providers may omit usage.cost. You can provide per-1M-token prices:

export PRICE_INPUT=1.75
export PRICE_OUTPUT=14
export PRICE_CACHE_READ=0.175
export PRICE_CACHE_WRITE=0
python3 {baseDir}/scripts/extract_cost.py --last-days 7

4) Budget alerts

The extractor can run as a budget check:

python3 {baseDir}/scripts/extract_cost.py --today --budget-usd 5
  • If budget is exceeded, it prints an ALERT and exits with code 2 (default).
  • For non-failing checks:
python3 {baseDir}/scripts/extract_cost.py --today --budget-usd 5 --budget-mode warn

Wiring it to a cron alert (recommended)

Run it daily (or hourly) and if exit code is 2, send yourself a Telegram message.

(Implementation depends on your OpenClaw channel setup; do not embed secrets in scripts.)

5) Token-saving playbook (teach the AI)

When the user says “use as few tokens as possible”, apply:

  • Default response budget: 1–6 lines, bullets > paragraphs
  • Ask 1 question max (only if truly blocking)
  • Progressive disclosure: offer details only if asked
  • Tool calls: batch; avoid repeated status/browser calls
  • No log dumps into chat; summarize + point to file path
  • Hard limits: max 3 web iterations (search/fetch) per task

Optional phrasing to keep yourself in check:

> "Answer in <=6 lines. If more is needed, ask permission."

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-03-28 12:05 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

OpenClaw Auto‑Updater (Safe + Scheduled + Summary)

dasweltall
使用可靠的 cron 模板、时区安全调度及清晰摘要输出,安排 OpenClaw 和技能的自动更新。适用于免维护管理、计划升级及简明更新报告。
★ 13 📥 14,364
ai-intelligence

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,350 📥 317,717
ai-intelligence

ontology

oswalpalash
类型化知识图谱,用于结构化智能体记忆与可组合技能。支持创建/查询实体(人员、项目、任务、事件、文档)及关联...
★ 709 📥 243,539