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

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

未關閉
#2,631 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
15.9k
分支
1.4k
平均合併
1 天 17 小時
30 天內合併 PR
163

描述

### 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.

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。