Skip to content

feat: add cost and usage tracking to output directory per step and overall task#600

Merged
ereslibre merged 1 commit intomainfrom
ereslibre/add-cost-to-output
Mar 27, 2026
Merged

feat: add cost and usage tracking to output directory per step and overall task#600
ereslibre merged 1 commit intomainfrom
ereslibre/add-cost-to-output

Conversation

@ereslibre
Copy link
Copy Markdown
Collaborator

@ereslibre ereslibre commented Mar 24, 2026

Add usage and cost tracking throughout the task lifecycle. Each iteration now records its usage (tokens, cost, model, agent) in iteration.json, and the task description aggregates usage across all iterations. The inspect command displays a new Usage section, and the list command syncs usage on every refresh.

Changes

Schemas (packages/schemas)

  • Added UsageReportSchema and StepUsageReportSchema Zod schemas in packages/schemas/src/usage/schema.ts
  • UsageReport and StepUsageReport types are now inferred from Zod schemas (z.infer<typeof ...>) instead of manually defined interfaces
  • Bumped IterationSchema to v1.2 with an optional usage field
  • Bumped TaskDescriptionSchema to v1.6 with an optional usage field
  • Exported UsageReportSchema, StepUsageReportSchema, and StepUsageReport from the package index

Core (packages/core)

  • IterationManager gains usage getter and setUsage() method; added migration from v1.1 → v1.2
  • TaskDescriptionManager.updateStatusFromIteration() now catches missing status.json gracefully and calls syncUsage() on terminal states
  • Added TaskDescriptionManager.syncUsage() that rebuilds task-level usage by summing iteration data via accumulateUsage()
  • Added usage getter to TaskDescriptionManager
  • Added private accumulateUsage() helper that sums two UsageReport values, resolving agent/model only when all reports agree
  • aggregateUsage in WorkflowManager now builds a per-step StepUsageReport[] breakdown and resolves top-level agent/model only when all steps agree
  • UsageTracker now tracks agent alongside model, with the same single-value-when-unanimous resolution strategy

Agent (packages/agent)

  • runCommand persists workflowUsage to iteration.json via IterationManager.setUsage()
  • ACP runner attaches agent (tool name) to usage reports alongside model
  • run command displays Agent in usage properties output

CLI (packages/cli)

  • inspect command calls task.updateStatusFromIteration() before display, includes usage in output, and renders a new Usage section (cost, input/output/total tokens)
  • list command comment updated to reflect usage sync on terminal states
  • Added usage field to TaskInspectionOutput interface

Notes

  • The task description schema version was bumped from 1.5 to 1.6; iteration schema from 1.1 to 1.2.
  • Top-level agent and model on aggregated reports are intentionally set only when all contributing steps/iterations used the same value; otherwise they are left undefined.
  • Usage is persisted only in iteration.json (versioned); status.json is not modified with cost data.

@ereslibre ereslibre self-assigned this Mar 24, 2026
@ereslibre ereslibre requested a review from Angelmmiguel March 24, 2026 11:06
@ereslibre ereslibre force-pushed the ereslibre/add-cost-to-output branch 3 times, most recently from 331a2f3 to 9588b17 Compare March 25, 2026 08:31
@ereslibre ereslibre force-pushed the ereslibre/add-cost-to-output branch from 9588b17 to dc7e9ac Compare March 25, 2026 08:57
Copy link
Copy Markdown
Contributor

@Angelmmiguel Angelmmiguel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Amazing we are reporting and storing all this data. This is mandatory for autonomous systems 😄

@ereslibre ereslibre merged commit 165b689 into main Mar 27, 2026
6 checks passed
@ereslibre ereslibre deleted the ereslibre/add-cost-to-output branch March 27, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants