docs(agent-workflows): Plan usage and cost telemetry - #5253
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🤖 The AI agent says: Please review the canonical runner-to-service usage shape, inclusive token and cache semantics, model-scoped cost provenance, and the phase boundary that requires CTO approval before any API-visible span attribution or semantic-convention change. The five open decisions are listed in status.md and the PR body. |
|
Closing — tracked under #5505. |
|
This design was closed without review. I had an independent staff-level reviewer (Codex, gpt-5.6, maximum reasoning effort, read-only over the repo) answer the five open decisions in VerdictThe semantic foundation is right, but the document is not implementation-ready. Approved as written: inclusive canonical input and output; explicit cost provenance; a documented Agenta cost extension; one incremental owner per usage observation; context occupancy kept separate from billable usage. Rejected or needing revision: the unresolved cross-batch strategy; arbitrary numeric-key rollups; the ambiguous temporality of The five decisions1. Cross-batch parent summaries. Export exactly one explicitly cumulative run summary on the SDK workflow root, derived from the runner's terminal result. Keep incremental usage only on leaf model-call spans. The root carries 2. Version skew. Yes, it can happen, and it is not hypothetical. Railway, Docker Compose and the Kubernetes chart all deploy the services and the runner as independently versioned artifacts. Add 3. First Vercel projection. Inclusive input, output and total only. Cache and reasoning stay internal. Exposing them now creates a second compatibility surface before the canonical schema is stable. 4. Rollup strategy. A generic reducer governed by a versioned bucket schema. Not arbitrary numeric keys. Each registered bucket declares its type, scope, temporality, rollup operation, parent-inclusion relationship, currency rule and missing-versus-zero rule. Cache-read tokens are additive across calls but already inside canonical input. Context occupancy is a gauge and needs latest-observation semantics. Costs can only be summed when the currency matches. Summing every number under 5. First UI change. Provenance of the total first, and not as a binary. Three honest labels: reported, harness-calculated, estimated by Agenta. Source and currency in the tooltip. If provenance is mixed, say "Mixed" and require a breakdown rather than presenting one homogeneous number. Defer cache and reasoning breakdowns, because they need transport, types, trace queries and completeness state, not just a visual change. The inclusive-versus-exclusive contradiction, settledThe design says It confirmed this by running the pinned litellm 1.92.0 with 93 uncached and 13,463 cache-read tokens:
The middle row silently loses the 93 ordinary tokens. Litellm derives ordinary input by subtracting the cache details from the prompt count it is given, so it expects the inclusive figure. This holds on both the OpenAI and the Anthropic pricing routes. What the July design did not answer, and an implementer hits on day oneWhich summary is authoritative and when it becomes final. What happens after cancellation or partial completion. Whether a later child batch may update a root. How a replay is prevented from replacing a newer final value. Whether ACP What is now obsoleteFour fixes landed this week, in #5708, #5709 and #5710. Context occupancy is no longer reported as token usage, though it is dropped rather than preserved as a gauge. A runner batch with an external parent no longer yields an empty tree, though rollup is still batch-local. Streaming span activation is repaired. Producer cost is no longer discarded, but that mapping is a compatibility workaround with ambiguous span scope, not a final contract, because the runner emits One thing to state plainly in the designThis is observability telemetry, not a billing ledger. If Agenta ever charges customers from these numbers, best-effort OTLP delivery, floating-point dollars, sampling and overwrite-on-retry storage are all unacceptable. Billing would need a durable idempotent usage ledger with integer minor units and invoice reconciliation. Worth writing down before someone assumes otherwise. Immediate follow-upShip the cached-cost fix in #5540 before the larger design, since it is a current correctness bug and can be tested against today's known exclusive runner semantics. That work is in progress and also carries two related defects the review surfaced: |
Context
Pi and Claude expose cache-aware token and cost information, but the agent runner reduces every
run to four ambiguous numbers. That loses cache buckets, currency, provenance, and model scope,
and it conflates ACP context-window occupancy with billed token usage. Tracing then repeats totals
on leaf and parent spans while the API recalculates producer-supplied cost, so the displayed cost
can be inaccurate or counted more than once.
This design starts at the pre-production harness, runner, and runner-to-service boundaries. It
keeps exported span attribution and service-to-API semantic-convention changes behind an explicit
CTO approval gate.
What this proposes
The runner normalizes each harness into inclusive input/output token totals with cache and
reasoning subcategories, monetary cost with currency and provenance, model-scoped observations,
and a separate context-utilization gauge. Pi and Claude adapters reconcile fields by authority and
temporality instead of replacing one whole usage object with another.
The plan also inventories the wider trace path: span hierarchy, model and response identity,
content policy, status/errors, timing, adapters, storage, rollups, query presets, and UI display.
It proposes one-owner incremental attribution and an Agenta cost semantic convention, but defers
all API-visible behavior changes until the CTO approves the convention, rollup, and cross-batch
strategy.
Before:
{"usage":{"input":10,"output":5,"total":15,"cost":0.001}}Proposed direction:
{ "usage": { "tokens": {"input":12000,"output":800,"total":12800,"details":{"cacheReadInput":10500}}, "costs": {"total":{"amount":0.021,"currency":"USD"},"provenance":{"kind":"reported","source":"provider"}} }, "context": {"usedTokens":12800,"windowTokens":200000} }How to review
context.mdfor scope and boundary constraints.research.mdandtrace-inventory.mdfor the end-to-end findings and deferred gaps.interface-design.md, especially inclusive token arithmetic, model-scoped costprovenance, final versus provisional events, and the service-to-API proposal.
plan.mdfor the runner-first sequence and the CTO gate before exported trace changes.qa.mdfor cache-heavy, multi-model, partial/error, streaming, and no-double-countingcoverage.
Decisions requested
public documentation.
Tests / notes
This PR contains design documents only. The research used the live runner, installed Pi and Claude
ACP packages, Python service contracts, API adapters and tree rollups, observability UI paths,
existing tests, and public tracing documentation.