Skip to content

Show a run summary with steps, time, tokens, and cost #15

Closed

Description

@vicgupta

Problem

tinyagent tracks step count and cost while it runs, and -o saves them, but the CLI never reports them. A successful run ends with nothing but the model's streamed text; a failed one prints <Status> after N steps and a hint. Users cannot tell how long a run took, how many tokens it used, or what it cost without opening the trajectory JSON — and that JSON does not even include token counts today, because the loop only accumulates Cost.USD.

This matters most for the limits that already exist: --step-limit, --cost-limit, and --time-limit. There is no feedback on how close a run came to them, and an expensive run gives no cost readout at the end.

Proposed behavior

Print one compact summary line to stderr whenever a run ends, for every exit status. Keep stdout for the model's text only, so redirecting it still yields a clean answer.

Examples:

Submitted after 12 steps in 1m42s (48,213 input / 3,104 output tokens, $0.23)

StepLimitExceeded after 50 steps in 6m03s (120,441 input / 11,209 output tokens, $1.87)

Error after 3 steps in 12s (4,120 input / 280 output tokens, $0.0043): HTTP 401: Incorrect API key
  • Status, steps, duration, and token counts are shown whenever they are known.
  • Cost appears only when it is greater than zero, so Codex subscription runs and unknown-priced models do not print a misleading $0.00. Format costs at or above one cent with 2 decimals, below one cent with 4.
  • Duration is wall-clock and human-readable (12s, 1m42s, 1h02m).
  • If a run ends before any model response (for example Ctrl-C during the first call), omit the token/cost parenthetical rather than printing zeros: Interrupted after 0 steps in 2s.
  • Keep the existing hint: line for setup errors.

Scope

  • internal/trajectory/trajectory.go: add InputTokens and OutputTokens fields (json:"input_tokens", json:"output_tokens"). This is additive, so existing consumers keep working.
  • internal/agent/loop.go: accumulate cost.InputTokens and cost.OutputTokens alongside t.Cost.
  • cmd/tinyagent/main.go: track the run's start time and print the summary for both success and failure. Keep exit codes and stdout behavior unchanged.
  • cmd/tinyagent/main_test.go: table-driven tests for the formatter (submitted, limit, error, zero cost, zero steps).
  • internal/agent/loop_test.go: assert token totals land in the trajectory.
  • README.md: mention the summary under "Exit status".

Acceptance criteria

  • Every run — Submitted, Completed, StepLimitExceeded, CostLimitExceeded, TimeLimitExceeded, Interrupted, Error — prints exactly one summary line to stderr.
  • The summary includes status, steps, elapsed time, and input/output token totals.
  • Cost is printed when non-zero and omitted at zero.
  • stdout still contains only the model's text; exit codes are unchanged.
  • Trajectories written with -o include matching input_tokens/output_tokens totals; existing JSON fields are unchanged.
  • go test ./... passes, and the README documents the new line.

This is a small, additive change: providers already return token counts in model.Cost, so it only extends end-of-run reporting and adds two trajectory fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readySmall, ready for a coding agentenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions