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

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

Đang mở
#2,631 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
15.9k
Fork
1.4k
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
163

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.