Skip to content

[BUG] A2A tasks always show 0 tokens: ADK drops the include_usage chunk #1526

Closed

Description

@edenreich

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

  1. Start the mock agent: go run . start in inference-gateway/mock-agent.
  2. 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
  3. 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:

  1. ADK drops the usage chunk (adk server/agent_streamable.go, RunWithStream, still on main). The gateway forces stream_options.include_usage=true for every streaming request (inference-gateway providers/core/provider.go prepareStreamingRequest). Per the OpenAI spec, the usage then arrives on a separate final chunk whose choices is an empty array. The ADK:

    • runs if streamResp == nil || len(streamResp.Choices) == 0 { continue } before if streamResp.Usage != nil { usageTracker.AddTokenUsage(...) }, so the usage chunk is skipped, and
    • sets streaming = false on the chunk with a finish_reason, which comes before the usage chunk, so the loop has stopped reading by the time usage arrives.

    Since UsageTracker.GetMetadata only emits usage when llmCalls > 0, the key is never written. This affects every Go ADK agent behind the gateway, not just the mock.

  2. mock-agent never sends usage on the streaming path (internal/mock/llm_client.go). CreateChatCompletion returns Usage{100, 50, 150}, but CreateStreamingChatCompletion (the only path the ADK uses) sends no Usage on any chunk. The mock cannot be used to test the fix until it emits a trailing choices: [] chunk with usage, like the gateway does.

  3. CLI shows 0 instead of "unknown" (internal/protocols/a2a/job.go taskRunStats). When usage is absent but execution_stats is present, the stats are built with zero tokens and rendered as · 0 tokens / Tokens: 0 in, 0 out (subagent_list.go statsTokens, 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-Extensions request header, which the agent echoes back

Work items:

Activity

  1. added theissue type on Oct 4, 2026
  2. added
    bug
    on Oct 4, 2026
  3. changed the title [-][BUG] CLI does not report A2A tokens usage properly[/-] [+][BUG] A2A tasks always show 0 tokens: ADK drops the include_usage chunk[/+] on Oct 4, 2026
  4. added 4 commits that reference this issue on Oct 4, 2026
    70dc344
    7b2a644
    d244b43
    371aef6
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

    bug

    Type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions