Skip to content

fix(workflow): expose totalUsage and finishReason on stream result#14786

Draft
VaguelySerious wants to merge 1 commit intoworkflow-agent-unify-callbacksfrom
peter/workflow-agent-stream-result-totalusage
Draft

fix(workflow): expose totalUsage and finishReason on stream result#14786
VaguelySerious wants to merge 1 commit intoworkflow-agent-unify-callbacksfrom
peter/workflow-agent-stream-result-totalusage

Conversation

@VaguelySerious
Copy link
Copy Markdown
Member

@VaguelySerious VaguelySerious commented Apr 28, 2026

Summary

WorkflowAgentStreamResult (the awaited return of agent.stream()) is missing totalUsage and finishReason. Both fields are already computed in the runtime and passed to the onFinish callback, so the omission from the result is asymmetric and diverges from GenerateTextResult/StreamTextResult, which expose them directly.

This adds them to the interface and to all three return sites (early-abort, paused-tools, and the final return), reusing the existing aggregateUsage(steps) helper.

Targets the workflow-agent-unify-callbacks branch since the WorkflowAgent work is gated behind it.

See also vercel/workflow#1863

Test plan

  • New regression test in workflow-agent-compat.test.ts asserts result.totalUsage and result.finishReason after a normal stream
  • Existing 107 tests still pass (108 with the new one), 5 expected-fails unchanged
  • pnpm turbo run build --filter=@ai-sdk/workflow passes

🤖 Generated with Claude Code

WorkflowAgentStreamResult omitted totalUsage and finishReason, which were
already computed and passed to the onFinish callback. This made them
unreachable for callers awaiting stream() directly, and diverged from
GenerateTextResult/StreamTextResult.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant