← 返回
数据分析 中文

Agent Usage Tracker

Track AI agent token usage, model costs, and budget thresholds with a TypeScript and SQLite workflow. Use when the user wants to instrument agent runs, calcu...
使用 TypeScript 与 SQLite 工作流追踪 AI 代理的 token 使用量、模型费用和预算阈值。适用于需要在代理运行时进行监控、成本计算等场景。
imgolye
数据分析 clawhub v0.1.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 568
下载
💾 8
安装
1
版本
#latest

概述

Agent Usage Tracker

Use this skill when you need local token accounting for AI agents.

What it provides

  • Real-time token usage persistence in SQLite
  • Cost calculation based on per-model pricing
  • Budget thresholds with persisted warning and blocking states
  • Usage statistics grouped by time window, session, or model

Files to use

  • src/UsageTracker.ts: ingestion, storage, and reporting
  • src/CostCalculator.ts: pricing catalog and cost math
  • src/BudgetManager.ts: budget policy evaluation
  • examples/basic-usage.ts: end-to-end usage example
  • tests/: reference behavior for tracking, budgeting, and aggregation

Recommended workflow

  1. Instantiate UsageTracker with a SQLite path or :memory: for tests.
  2. Register model pricing with CostCalculator.
  3. Record each agent interaction with prompt tokens, completion tokens, session id, and timestamp.
  4. Save reusable budgets with BudgetManager.setBudget, then call evaluateBudget before or after new work to warn or stop when a limit is exceeded.
  5. Use UsageTracker.getUsageSummary or getTimeSeries for reporting.

Integration notes

  • Store token counts at the moment the provider returns usage metadata.
  • Keep model ids normalized. Pricing lookup is exact by model id.
  • Use metadata for provider-specific fields such as request id or tool name.
  • For sliding-window budgets, query usage by startTime and endTime before dispatching new work.

Output expectations

This skill ships as a local Node.js package with tests and examples. Extend CostCalculator if your provider pricing changes.

版本历史

共 1 个版本

  • v0.1.0 当前
    2026-03-30 13:43 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

data-analysis

Excel / XLSX

ivangdavila
创建、检查和编辑 Microsoft Excel 工作簿及 XLSX 文件,支持可靠的公式、日期、类型、格式、重算及模板保留功能。
★ 368 📥 140,466
ai-intelligence

Daily Hot Push

imgolye
每日推送中国热榜TOP10到飞书。从微博、知乎、百度、36氪筛选最重要的新闻,智能排除明星八卦和主观评论。
★ 2 📥 2,542
data-analysis

A股量化 AkShare

mbpz
A股量化数据分析工具,基于AkShare库获取A股行情、财务数据、板块信息等。用于回答关于A股股票查询、行情数据、财务分析、选股等问题。
★ 165 📥 60,018