npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cripticweb3/agent-ledger

v1.0.0

Published

AI agent call ledger. Track every tool call, LLM request, cost, and outcome. In-memory by default, exportable to JSON/CSV. The Stripe dashboard for your agents.

Readme

agent-ledger

AI agent call tracking, cost analysis, and audit log. Wrap any tool or LLM call. Full ledger in memory. Export to JSON or CSV. The Stripe dashboard for your agents. Zero dependencies.

npm version license zero dependencies

Built by Brennan Zambo — extracted from the observability layer running inside zambo.dev's 28-tool MCP server.


What it does

Every AI team running autonomous agents has the same problem: you don't know what they're doing or what it's costing until something breaks or the bill arrives. agent-ledger wraps any async function — LLM calls, tool calls, API calls — and records every invocation in a structured ledger.

One report() call tells you total cost, success rate, slowest tools, which providers are being hit, and how many tokens you've burned.


Install

npm install agent-ledger

Zero dependencies. Node.js 18+. Works in any runtime.


Quick start

import { AgentLedger } from 'agent-ledger';

const ledger = new AgentLedger();

// Wrap any async function
const trackedSearch = ledger.wrap(searchWeb, 'web_search', { costUsd: 0.001 });
const trackedAudit  = ledger.wrap(auditCode, 'code_audit', {
  provider: 'groq',
  model: 'llama-3.3-70b-versatile',
  extractCost: (result) => result.costUsd ?? null,
  extractTokens: (result) => ({ input: result.inputTokens, output: result.outputTokens }),
});

// Use exactly like the original functions
const searchResult = await trackedSearch({ query: 'AI agent payments' });
const auditResult  = await trackedAudit({ code: myCode });

// Get a full report
const report = ledger.report();

console.log(`Total calls:   ${report.total}`);
console.log(`Success rate:  ${(report.successRate * 100).toFixed(1)}%`);
console.log(`Total cost:    $${report.totalCostUsd.toFixed(4)}`);
console.log(`Avg latency:   ${report.avgDurationMs}ms`);
console.log(`Total tokens:  ${report.totalTokens.input}in / ${report.totalTokens.output}out`);

Global singleton

import { getLedger } from 'agent-ledger';

// Same instance anywhere in your app
const ledger = getLedger();

Report breakdown

const report = ledger.report();

// By tool
console.log(report.byTool['web_search']);
// { calls: 142, errors: 3, avgDurationMs: 847, totalCostUsd: 0.142 }

// By provider
console.log(report.byProvider['groq']);
// { calls: 891, totalCostUsd: 0.0087 }

// By status
console.log(report.byStatus);
// { success: 1204, error: 12, timeout: 3 }

Filter by time window:

const last24h = ledger.report(Date.now() - 86_400_000);

Export

// JSON
import { writeFileSync } from 'fs';
writeFileSync('agent-log.json', ledger.toJSON());

// CSV (open in Excel / Sheets)
writeFileSync('agent-log.csv', ledger.toCSV());

CSV columns: id, tool, startedAt, completedAt, durationMs, status, costUsd, provider, model, inputTokens, outputTokens, error, inputSummary


Manual recording

For tools you can't wrap directly:

ledger.record({
  id: 0, // auto-assigned, but required for type
  tool: 'vector_search',
  startedAt: Date.now() - 234,
  completedAt: Date.now(),
  durationMs: 234,
  status: 'success',
  costUsd: 0.0001,
  provider: 'pinecone',
  model: 'text-embedding-3-small',
  inputTokens: 128,
  outputTokens: 0,
});

WrapOptions

interface WrapOptions {
  costUsd?: number;                          // static cost per call
  provider?: string;                         // e.g. 'groq', 'anthropic'
  model?: string;                            // e.g. 'llama-3.3-70b'
  extractCost?: (result) => number | null;   // dynamic cost from result
  extractTokens?: (result) => { input?, output? } | null;
  summarizeInput?: (args) => string;         // privacy — default: first 200 chars
  meta?: Record<string, unknown>;            // arbitrary metadata
  timeoutMs?: number;                        // timeout in ms (status → 'timeout')
}

Persist to disk

const ledger = new AgentLedger({
  persistTo: './agent-log.json',   // written after every entry
  maxEntries: 50_000,              // FIFO eviction (default: 10,000)
  onEntry: (entry) => {
    if (entry.status === 'error') alertSlack(entry);
  },
});

With MCP tools

import { AgentLedger } from 'agent-ledger';
import { cascade } from 'ai-cascade';

const ledger = new AgentLedger();

const trackedCascade = ledger.wrap(
  (opts) => cascade(opts),
  'llm_cascade',
  {
    extractCost:   (r) => r.costUsd,
    extractTokens: () => null,
    provider:      'multi',
  }
);

// Every LLM call now tracked automatically
const result = await trackedCascade({ providers, messages });

Related

  • ai-cascade — multi-provider LLM fallback (pairs perfectly)
  • mcp-shield — security middleware for MCP servers
  • mcp-pay — x402 billing for MCP tools
  • zambo.dev — 28 MCP tools with agent-ledger tracking in production

License

MIT © Brennan Zambo