Repository navigation
Description
Summary
A2A tasks always show 0 tokens in the CLI: the subagent list renders · 0 tokens and the task view renders Tokens: 0 in, 0 out, even when the remote agent made several LLM calls. The CLI reads the counts correctly from task.metadata.usage (internal/protocols/a2a/job.go taskRunStats). The problem is that Go ADK agents never put a usage key in the task metadata, so the CLI falls back to zeros. Only execution_stats arrives.
Reproduced on 2026-10-04 with mock-agent v0.4.11 (ADK v0.32.2) and cli main (ADK v0.32.2).
Steps to Reproduce
- Start the mock agent:
go run . startininference-gateway/mock-agent. - Send a task and read it back:
curl -s localhost:8080/a2a -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"1","method":"SendMessage","params":{"message":{"role":"ROLE_USER","parts":[{"text":"read go.mod"}],"messageId":"m1"}}}' curl -s localhost:8080/a2a -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":"2","method":"GetTask","params":{"id":"<task id>"}}' | jq .result.metadata
- Delegate the same prompt to the mock agent from
infer chat(A2A agent configured), then open the task view. The row shows· 0 tokens.
Observed metadata of the completed tasks for read go.mod and echo hello (each made 2+ LLM calls):
{"execution_stats":{"failed_tools":0,"iterations":3,"messages":1,"tool_calls":1}}
{"execution_stats":{"failed_tools":0,"iterations":7,"messages":1,"tool_calls":1}}Step 3 was verified at the unit level: feeding that metadata to the CLI's taskRunStats gives Tools: 1 succeeded, 0 failed | Tokens: 0 in, 0 out.
Expected Behavior
The task metadata carries usage.prompt_tokens / usage.completion_tokens summed across every LLM call of the task, and the CLI shows them in the subagent list and the task view. A row whose agent reported no usage should not claim 0 tokens.
Actual Behavior
usage is missing from the metadata, so every A2A row shows 0 tokens. Root causes, in order of impact:
-
ADK drops the usage chunk (
adkserver/agent_streamable.go,RunWithStream, still onmain). The gateway forcesstream_options.include_usage=truefor every streaming request (inference-gatewayproviders/core/provider.goprepareStreamingRequest). Per the OpenAI spec, the usage then arrives on a separate final chunk whosechoicesis an empty array. The ADK:- runs
if streamResp == nil || len(streamResp.Choices) == 0 { continue }beforeif streamResp.Usage != nil { usageTracker.AddTokenUsage(...) }, so the usage chunk is skipped, and - sets
streaming = falseon the chunk with afinish_reason, which comes before the usage chunk, so the loop has stopped reading by the time usage arrives.
Since
UsageTracker.GetMetadataonly emitsusagewhenllmCalls > 0, the key is never written. This affects every Go ADK agent behind the gateway, not just the mock. - runs
-
mock-agent never sends usage on the streaming path (
internal/mock/llm_client.go).CreateChatCompletionreturnsUsage{100, 50, 150}, butCreateStreamingChatCompletion(the only path the ADK uses) sends noUsageon any chunk. The mock cannot be used to test the fix until it emits a trailingchoices: []chunk withusage, like the gateway does. -
CLI shows
0instead of "unknown" (internal/protocols/a2a/job.gotaskRunStats). Whenusageis absent butexecution_statsis present, the stats are built with zero tokens and rendered as· 0 tokens/Tokens: 0 in, 0 out(subagent_list.gostatsTokens,task_management_view.go). The token figures should be hidden when the agent did not report usage.
Side notes: the ADK never reports cached_tokens, so SubagentRunStats.CachedTokens is always 0 for A2A tasks. The CLI also does not add A2A task usage to the session token totals. Tracking that is a separate decision.
Suggested fix
The A2A spec has no usage field. Its recommended route for custom data is an extension, so usage moves from the bare usage / execution_stats keys to the usage extension (https://github.com/inference-gateway/schemas/tree/main/a2a/extensions/usage/v1):
- metadata keys namespaced by the URI (
<URI>/usage,<URI>/execution_stats) - declared in the Agent Card with
required: false - inactive unless the client lists the URI in the
A2A-Extensionsrequest header, which the agent echoes back
Work items:
-
schemas: extension spec (docs(a2a): add the usage extension spec schemas#279, merged). -
adk: count the trailingchoices: []usage chunk, drain the stream afterfinish_reason, requestinclude_usage, and publish usage as the extension with header activation and the card declaration (feat(server): count streamed usage and publish it as an A2A extension adk#397, released in v0.33.0). -
mock-agent: end streams with achoices: []usage chunk (fix(mock): end streams with an include_usage chunk mock-agent#167). -
cli: hide token figures when no usage was reported (fix(a2a): show A2A task usage through the usage extension #1529). -
cli, after the ADK release (fix(a2a): show A2A task usage through the usage extension #1529):- bump the ADK
- set
A2A-Extensions: adk.UsageExtensionURIin the client factory (internal/protocols/a2a/infrastructure/client.go) - read
adk.UsageMetadataKey/adk.ExecutionStatsMetadataKeyinjob.gotaskRunStatsandsubmit_task.goappendTaskMetadataLines - update
docs/a2a-connections.md
-
rust-adk: same extension, plusClientConfig::extensionsso its client can activate it (feat(server): publish task usage as an A2A extension rust-adk#227). Its stream already counted the trailing usage chunk. -
typescript-adk: same extension, withwithUsageExtension(card)for hand-wired servers and gating of the terminal status frames too (feat(server): publish task usage as an A2A extension typescript-adk#275). Its handlers take usage from a non-streaming completion, so no stream fix was needed. -
adl-cli: bump the Go ADK pin to v0.33.0 so generated Go agents serve the extension (chore(deps): bump the go adk to the usage extension release adl-cli#481). After the Rust and TypeScript releases, bump those pins and wrap the TS template's card inwithUsageExtension(card). -
adl: note in the A2A guide that the runtime declares card extensions such as the usage extension, since ADL has no manifest field for them (docs: note that the runtime declares card extensions adl#212). -
docs: document the extension ina2a.md,adk.md,rust-adk.mdandtypescript-adk.md(docs(a2a): document the usage extension docs#982, merge after the Rust, TypeScript and CLI PRs ship).
Activity
[-][BUG] CLI does not report A2A tokens usage properly[/-][+][BUG] A2A tasks always show 0 tokens: ADK drops the include_usage chunk[/+]docs(a2a): add the usage extension spec (#279)
feat(server): count streamed usage and publish it as an A2A extension (…
chore(release): 🔖 0.33.0 [skip ci]
fix(a2a): activate the usage extension and read its keys
fix(a2a): activate the usage extension and read its keys
feat(server): publish task usage as an A2A extension (#227)
feat(server): publish task usage as an A2A extension (#275)
chore(release): 🔖 0.20.0 [skip ci]
chore(release): 🔖 0.18.0 [skip ci]
chore(deps): bump the go adk to the usage extension release (#481)
fix(a2a): show A2A task usage through the usage extension (#1529)
chore(release): 🔖 0.66.4 [skip ci]
fix(mock): end streams with an include_usage chunk (#167)
chore(release): 🔖 0.4.14 [skip ci]