Repository navigation
Conversation
A runtime that reports a turn's cost (Claude Code's total_cost_usd, one process per turn) puts it on the turn's final status message as costUsd of kagent.dev/a2a/usage. The task store counts it when it publishes that boundary, once per boundary, in kagent.session.turn.cost.usd (kagent_session_turn_cost_usd_total) with k8s.namespace.name and gen_ai.agent.name of the Session's Agent and enduser.id, the Session's creator, so spend can be bounded and alerted per person. A runtime that reports no cost (Codex) counts nothing; a malformed usage is logged. Signed-off-by: Timo Derstappen <teemow@gmail.com>
Signed-off-by: Timo Derstappen <teemow@gmail.com>
Draft
3 of 5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The platform wants to see and alert on what one person's coding agent Sessions spend. Each turn's runtime already reports its cost on the turn's final status message (
costUsdofkagent.dev/a2a/usage, Claude Code'stotal_cost_usd, one process per turn), but nothing counted it where Prometheus scrapes, and nothing tied it to the Session's creator.Proposed solution
go/api/a2a:TurnCostUSDOfreads the reported cost from a status message; absent means not reported (Codex), a non-object usage or a cost that is not a finite non-negative number is malformed.kagent.session.turn.cost.usd(unit{USD}) →kagent_session_turn_cost_usd_total{k8s_namespace_name, gen_ai_agent_name, enduser_id},enduser.idbeing the Session's creator.The creator as a label is deliberate: spend is bounded per person, and the label's cardinality is the number of people who create Sessions. It puts a person's identity into the controller's metrics; that trade-off is open for review and changes forward if decided otherwise. Documented in
docs/architecture/runtime-and-lifecycle.md("Turn cost metrics").Acceptance criteria
TestTurnCostUSDOf(reported, absent, malformed),TestSettleTaskCountsTheTurnCostOfAPublishedBoundaryOncePerCreator(through the Prometheus exporter: the scraped name, the labels, counted once over a retried settlement),TestSettleTaskCountsNoCostARuntimeDoesNotReport;make -C go lint0 issues;scripts/fork/carried.sh --checkclean.kagent_session_turn_cost_usd_totalwith the turn's cost and creator, and the spend alert fires on it: pending.