微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🛡️

AI智能体成本守卫与预算管控

Lemnos Cost Guard · v1.2.2
效率 安全 A 级 作者 getlemnos32 公开目录收录
1k 下载 0 安装 4k 收藏 16 浏览

简介

专为OpenClaw智能体设计的实时API成本追踪工具,提供预算强制限制、上下文膨胀检测及模型路由建议,已获328+安装验证。

原始描述

Real-time API cost tracking, context bloat detection, and budget enforcement for OpenClaw agents. Use when setting up cost guardrails, checking daily spend,...

通过你的 Agent 添加

安装目录:lemnos-cost-guard/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。

点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。

或者手动安装

Claude Code~/.claude/skills/lemnos-cost-guard/
Codex CLI~/.codex/skills/lemnos-cost-guard/
DeepSeek Harness~/.agents/skills/lemnos-cost-guard/

包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可; 目录名不用换,也不要把包直接解压到 skills 根目录。 技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。

中文使用说明 来自收录源

核心用法

Lemnos Cost Guard 是一款面向 OpenClaw 智能体生态的专业成本管理工具,采用会话级成本追踪机制。核心工作流包含三个脚本模块:

  1. track_cost.py — 任务后立即记录token消耗,支持 --task/--input/--output/--model 参数,输出为 JSONL 格式的结构化日志
  2. cost_report.py — 生成日/周/月成本汇总,内置预算阈值检测(默认$5/日)
  3. context_analyzer.py — 扫描工作目录识别上下文膨胀,当 I/O 比例超过50:1时触发压缩建议

系统配套 references/model_pricing.md 定价表,实现智能模型路由:简单任务自动降级至 Haiku($0.8/M输入),默认使用 Sonnet($3/M输入),Opus 需显式授权。

显著优点

  • 实时预算强制:≥80%预算触发警告并暂停非创收任务,≥100%执行硬停止
  • 上下文优化:通过细粒度上下文加载规则(按任务类型限定文件范围)减少无效token消耗
  • 异常检测:单调用>500K输入token即时告警,防止突发高额账单
  • 生态集成:原生支持 OpenClaw 的 session_status delta 计算,日志格式兼容 ClawHub 分析标准

潜在局限

  • 定价表需手动维护,模型调价时存在滞后风险
  • 上下文加载规则依赖人工配置,复杂多任务场景可能遗漏依赖文件
  • 免费层仅支持日追踪,周/月汇总及自动化路由属付费功能($40-60/月)
  • 目前仅覆盖 Anthropic 系列模型定价,多厂商混合使用需自行扩展

适合人群

  • 一人公司/独立开发者:需严格控制API支出的个体经营者
  • AI运营团队:管理多智能体集群的中型技术团队
  • 成本敏感型SaaS:按token计费模式下需精细化成本核算的产品

常规风险

  1. 预算绕过风险:硬停止机制依赖工具层实现,底层API调用仍可能产生费用
  2. 日志完整性:JSONL本地存储存在单点故障,建议配置外部持久化
  3. 模型路由误配:自动降级策略可能影响输出质量,需定期复核任务分类准确性
  4. 隐私合规:成本日志含任务描述字段,需评估是否落入GDPR个人数据范畴

技能正文


name: lemnos-cost-guard description: "Real-time API cost tracking, context bloat detection, and budget enforcement for OpenClaw agents. Use when setting up cost guardrails, checking daily spend, logging token usage after a task, analyzing context bloat, generating cost reports (daily/weekly/monthly), getting model routing recommendations, or when a user asks about API costs, budget status, or why costs are high. 适用于一人公司和AI运营团队的实时成本监控工具。防止API成本失控。328+次安装。"

Lemnos Cost Guard

Track token usage, enforce budgets, detect context bloat, and route to cheaper models.

Quick Reference

Script Purpose
scripts/track_cost.py Log a cost entry after a task
scripts/cost_report.py Generate cost summary
scripts/context_analyzer.py Scan workspace for bloat

Pricing and model routing rules: references/model_pricing.md

Workflow

After Every Significant Task

Log cost immediately using session delta (session_status before vs after):

python3 skills/lemnos-cost-guard/scripts/track_cost.py \
  --task "email batch" \
  --input 45000 \
  --output 1200 \
  --model claude-sonnet-4-6

Logs to: logs/cost-YYYY-MM-DD.jsonl

Daily Briefing — Cost Summary Block

Run before sending the morning briefing:

python3 skills/lemnos-cost-guard/scripts/cost_report.py --days 1 --budget 5.00 --format brief

Include output verbatim in briefing. Flag anything over 80% of budget.

Budget Alerts

  • ≥80% of $5/day → warn user, pause non-revenue tasks
  • ≥100% of $5/day → hard stop, notify user immediately
  • Single call >500K input tokens → immediate alert
  • I/O ratio >50:1 → context bloat warning, recommend compaction

Context Bloat Check (run weekly or when costs spike)

python3 skills/lemnos-cost-guard/scripts/context_analyzer.py \
  --workspace /root/.openclaw/workspace

Context Loading Rules (enforce on every session)

Load ONLY what the current task requires:

Task Load
Morning briefing SOUL.md, USER.md, MEMORY.md, HEARTBEAT.md, today's memory
Email outreach MEMORY.md (Lemnos rules only), sent-log.md
LinkedIn research sent-log.md only
Crypto/market MEMORY.md (crypto section only)
Heartbeat (nothing to do) HEARTBEAT.md only

Do NOT load full MEMORY.md + all skills + all reference files unless the task requires it.

Model Routing

See references/model_pricing.md for full table. Quick rules:

  • Simple tasks (format, classify, status check) → Haiku ($0.80/M input)
  • Default → Sonnet ($3/M input)
  • Opus → never, unless explicitly requested

Cost Log Format

Each entry in logs/cost-YYYY-MM-DD.jsonl:

{
  "ts": "2026-02-24T18:00:00Z",
  "task": "email batch send",
  "model": "claude-sonnet-4-6",
  "input_tokens": 45000,
  "output_tokens": 1200,
  "ratio": 37.5,
  "cost_usd": 0.153,
  "notes": "batch 1 + batch 2"
}

⭐ If This Saves You Money

Star it on ClawHub — it helps others find it: https://clawhub.ai/skills/lemnos-cost-guard

Source Code

GitHub: https://github.com/getlemnos32/cost-guard

ClawHub Distribution

Free tier: daily cost tracking + budget alerts Premium ($40-60/mo): full dashboards, model routing automation, context optimization reports, weekly/monthly rollups

Skill file: lemnos-cost-guard.skill

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

cost-trackingapi-managementbudget-controltoken-optimizationopenclaw-ecosystemcontext-management

同类 Skill