Search by

adachsoft / agent-usage-report

Arkadiusz Adach

Generates structured JSON reports for agent model usage across workflows, conversations, and tasks.

Package info

gitlab.com/a.adach/agent-usage-report

Issues

pkg:composer/adachsoft/agent-usage-report

Statistics

Installs: 11

Dependents: 1

Suggesters: 0

Stars: 0

v0.1.0 2026-11-29 22:15 UTC

This package is auto-updated.

Last update: 2026-11-29 21:15:55 UTC


README

adachsoft/agent-usage-report builds a versioned JSON report from the model usage ledger and completed agent-run log. It is framework-independent and has no dependency on application, workflow, or task classes.

Main capabilities

  • Generate reports for workflow runs, conversations (including recursively related child conversations), and tasks.
  • Aggregate model and tool calls, token usage, exact decimal costs, cache misses, agent runs, and elapsed duration.
  • Represent agent runs as a hierarchy with per-run and descendant-inclusive totals.
  • Serialize reports to the documented JSON v1 format, with a matching JSON Schema in schema/.

Installation

Install the package with Composer:

composer require adachsoft/agent-usage-report

Requirements

  • PHP 8.3 or later.
  • The BCMath extension.
  • adachsoft/model-usage-ledger for the ledger and completed-run log contracts.

Creating and serializing a report

Inject AgentUsageReportGeneratorInterface and AgentUsageReportJsonSerializer:

$report = $generator->forWorkflowRun($rootRunId);
$json = $serializer->serialize($report);

The generator also provides forConversation($conversationId) and forTask($taskId). Workflow-run and task scopes use their corresponding ledger identifiers. A conversation scope includes entries in that conversation and recursively includes entries whose parent_conversation_id points into the selected conversation subtree.

JSON format

The serializer emits agent-usage-report/v1; its JSON Schema is available at schema/agent-usage-report-v1.schema.json.

The report contains:

  • A scope, generation timestamp, and period derived from usage entries and run records.
  • A summary of model calls, tool calls, tokens, costs, agent runs, cache misses, and elapsed period duration.
  • Per-agent totals, including subagents.
  • A run tree grouped by agent_run_id, with each node's own usage (self) and usage including descendants (total).

Costs are decimal strings summed exactly with BCMath and grouped by currency. A usage entry without a cost amount makes its aggregate's cost_is_complete false. A cache miss is a model call whose cached input is less than half the input-token count of the previous call in the same conversation, ordered by recorded_at; the first call in a conversation is not a miss. A missing cached-token count is treated as zero. cache_miss_cost contains the exact cost of calls classified as cache misses, grouped by currency. Legacy entries without an agent_run_id are combined into a synthetic unknown run for each conversation and agent pair. Missing run-log records do not prevent report generation; run metadata is null when unavailable.

Dependencies

The package depends only on adachsoft/model-usage-ledger and BCMath. Applications provide that package's ledger and run-log implementations; this package does not read application, workflow, or task repositories directly.