Skip to content

ROADMAP-06 — P0 — Turn token usage is written to every tool-call step row (double counting) #98

Open

Description

@getdownandcode

Series: ROADMAP — filed from the 2026-10-27 whole-project assessment · Backlog task: M14-T06 · Priority: P0 · Effort: extra small

Problem

When a turn requests multiple tool calls, the entire turn's usage is written onto every generated step row: sum(steps.input_tokens) > runs.total_input_tokens. Any dashboard or cost report built by summing steps lies; runs totals are correct by accident.

There is also no model/cost attribution anywhere (tracked separately in ROADMAP-12) — this issue fixes the attribution math only.

Evidence

  • agentkit/core/agent.py:394–407 — per-step trace write copies response.usage.input_tokens/output_tokens onto each tool-call step
  • agentkit/db/models.py — steps.input_tokens, runs.total_input_tokens

Suggested fix / acceptance criteria

  • A turn's usage is recorded once (turn-level step), per-call step rows carry per-call latency/outcome only (0 for token columns or a shared-usage marker chosen by design)
  • Invariant test: for any run, sum(steps.*) <= runs.total_* holds with equality semantics documented
  • Existing trace consumers/tests updated

Suggested branch / commit

fix/step-token-attribution · fix(core): record turn token usage once, not per tool-call step

Activity

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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions