ag-ui-protocol / ag-ui-protocol/ag-ui

[Feature]: @ag-ui/claude-agent-sdk: forward modelUsage in the run result envelope

Offen
#2,631 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
15.9k
Forks
1.4k
Ø Merge
1 T. 17 Std.
Gemergte PRs (30 T.)
163

Beschreibung

### Pre-flight Checklist

- [x] I have searched existing issues and this hasn't been requested yet.

### Problem or Motivation

The result envelope (`lastResultData`) built in the `result` branch of
`streamMessages` in `@ag-ui/claude-agent-sdk` copies `usage` and
`total_cost_usd` from the SDK's `SDKResultMessage` but drops
`resultMsg.modelUsage`. That field (`Record`) carries
per-model token counts.

Consumers pricing non-Claude / gateway-routed turns cannot get per-model usage:
the single `total_cost_usd` misprices them, and the aggregate `usage` object does
not distinguish models. The data exists on the SDK result but never reaches the
`RUN_FINISHED` result envelope.

### Proposed Solution

Forward `modelUsage` in the result envelope — a one-line additive change: add
`modelUsage: resultMsg.modelUsage` to the `lastResultData` object, alongside the
already-forwarded `usage` and `total_cost_usd`. Both `SDKResultSuccess` and
`SDKResultError` carry `modelUsage` (camelCase). When the SDK omits it the value
is `undefined`, so there is no behavior change for existing consumers.

### Alternatives Considered

Consumers could re-derive per-model usage from raw SDK messages, but the adapter
already assembles the result envelope and drops only this field; forwarding it is
the natural place and costs one line.

### Additional Context

A PR is opened alongside this issue.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.