文档

agentic-ledger

试用

Track every token and dollar your OpenClaw agent spends, set budget walls that actually refuse calls, and replay runs on free local models. Local-first: all data stays on this machine. Use when the user asks about cost, spend, tokens, budgets, usage reports, or what the agent has been doing.

它能做什么

Track every token and dollar your OpenClaw agent spends, set budget walls that actually refuse calls, and replay runs on free local models. Local-first: all data stays on this machine. Use when the user asks about cost, spend, tokens, budgets, usage reports, or what the agent has been doing.

技能文档

Agentic Ledger

What this is

Agentic Ledger is a small local proxy that sits between OpenClaw and the model provider. Every call is recorded on this machine: the prompt, the response, tokens, cost, latency, and errors. It can also refuse calls once a budget line is crossed, which a dashboard alone cannot do. No account, no cloud, no telemetry.

Setup (one time)

Run these on the host machine (not inside the OpenClaw container):

pip install agentic-ledger
agenticledger start
agenticledger connect openclaw

If agenticledger is not on PATH after the install, it lives inside the virtualenv you installed into: run it as /bin/agenticledger.

connect openclaw finds the OpenClaw config, backs it up, and points the model provider's base URL at the proxy. It detects Docker installs and uses host.docker.internal automatically, because localhost inside a container is the container itself. Restart the OpenClaw gateway afterwards so the new config loads.

No upstream configuration is needed: the ledger (0.8.1 and later) routes each call to the provider matching its wire format, so Anthropic and OpenAI agents both work out of the box. Only for a custom gateway or a pre-0.8.1 ledger, set it explicitly and restart:

agenticledger config set proxy.upstream_url 
agenticledger stop && agenticledger start

Optional but recommended so cost questions run without an approval prompt each time (this is what the ledger reads need; it pre-approves only curl):

openclaw approvals allowlist add --agent main "/usr/bin/curl"

Verify: the ledger's /health should answer (see "Finding the ledger's address" below), and after the agent's next message $LEDGER/api/sessions should show a session. The dashboard lives at http://localhost:8000 in the host's browser.

The ledger never stores the provider API key. OpenClaw keeps its own credentials; the proxy forwards them per call.

Finding the ledger's address

On a bare install the ledger is at http://localhost:8000. Inside Docker, localhost is the container itself, so the ledger is at http://host.docker.internal:8000. Test with /health and use whichever answers:

curl -s -m 3 http://localhost:8000/health || curl -s -m 3 http://host.docker.internal:8000/health

Use the address that worked as LEDGER in everything below.

Answering cost questions

When the user asks what things cost or what the agent did, read from the ledger, never estimate:

curl -s "$LEDGER/api/reports?days=7"
curl -s "$LEDGER/api/runs"
curl -s "$LEDGER/api/sessions"

If an access key is configured, add -H 'x-agenticledger-api-key: '.

Report in plain words: total spend for the window, the per-model breakdown largest first, error counts (amber "blocked" calls are the budget wall working, not failures), and cache savings when notable. For loops, give iterations so far and the spend rate.

When an exec approval prompt appears for one of these reads, ask the user to approve it, and in the same breath tell them the one-liner that stops the asking permanently (it pre-approves only curl, nothing else):

openclaw approvals allowlist add --agent main "/usr/bin/curl"

If exec approval is unavailable or misbehaving (approvals loop without executing), do not guess numbers. Either use a web fetch tool on the same URLs (they are plain GET endpoints returning JSON) or hand the user this one command to run on the host and paste back:

curl -s "http://localhost:8000/api/reports?days=7"

Budget walls

To cap spending, set budgets in the ledger config and restart it:

agenticledger config set budgets.daily 5.00
agenticledger config set budgets.session 1.00

On OpenClaw setups, also set the refusal status to 402. OpenClaw reads a 429 as a rate limit and retries it over and over (observed live: one question became twelve wall-hits); 402 is a final no that nothing retries:

agenticledger config set budgets.status 402

Once a wall is hit, the proxy answers the call with a clear refusal instead of forwarding it, and the dashboard shows the blocked calls in amber. This is a hard stop, not an alert.

Replay: try a cheaper model on a real run

The dashboard can re-run a captured session or a whole run on another model, including a free local one (LM Studio or any OpenAI-style server), and grade the result: how many moments matched, which fumbled, and cost totalled both ways. Point the user at http://localhost:8000 in their browser, pick the run, choose Replay. Useful before switching models: see whether the cheap model would have survived the actual workload, not a benchmark.

相关技能

Track LLM API spending per agent/session with budget alerts and CSV export

1 次安装

把 OpenClaw 每次模型调用的 token 用量与费用落到 SQLite 的审计型账本。

28 次安装

Track, aggregate, and report OpenClaw token usage and costs across sessions.

Give your OpenClaw agent a wallet and a credit score. Hire other AI agents (on-chain escrow, independent grading, pay-only-on-pass) or earn as a worker on th...

Build, bootstrap, and maintain a stable OpenClaw default agent identity by interviewing the user, updating IDENTITY.md, and seeding core context files (AGENT...

28 次安装

OpenClaw usage and performance reporting. Parse session JSONL to answer how long each agent task took, which tools/skills/models were used, and how many tokens were consumed — zero dependency, local only, no cost dimension (token is the primary metric). Read-only: never modifies any file, aggregates statistics only, never leaks conversation content. Use when the user asks about token usage, task duration, slowest tools, skill usage, or per-agent consumption (今天花了多少 token/哪个工具最慢/ 任务耗时/用量报告), or scheduled via cron. 中文:OpenClaw 用量与性能查询。 解析 session JSONL,回答每次 agent 任务耗时、所用工具/技能/模型、token 消耗。零依赖纯本地,不提供成本维度(token 为主指标)。只读:不修改任何 文件,只输出聚合统计,不泄露会话内容。用户问 token 用量、任务耗时、 最慢工具、技能使用、按 agent 消耗时使用。cron 每日日报为可选项,用户 自行设置。