fix(ai): change createAgentUIStream onStepFinish to UIMessageStreamOnStepFinishCallback#12978
Open
sleitor wants to merge 1 commit intovercel:mainfrom
Open
fix(ai): change createAgentUIStream onStepFinish to UIMessageStreamOnStepFinishCallback#12978sleitor wants to merge 1 commit intovercel:mainfrom
sleitor wants to merge 1 commit intovercel:mainfrom
Conversation
…StepFinishCallback The onStepFinish callback in createAgentUIStream, createAgentUIStreamResponse, and pipeAgentUIStreamToResponse was typed as ToolLoopAgentOnStepFinishCallback (LLM-level step result), which differs from the UIMessageStreamOnStepFinishCallback (UI-level messages, isContinuation, responseMessage) used in createUIMessageStream. This commit: - Changes the onStepFinish type in all three agent UI stream functions to UIMessageStreamOnStepFinishCallback for API consistency - Moves onStepFinish from agent.stream() to result.toUIMessageStream() so it receives the processed UI messages instead of raw LLM step results - Adds onStepFinish to UIMessageStreamOptions so it can be passed through toUIMessageStream(), pipeUIMessageStreamToResponse(), and toUIMessageStreamResponse() - Adds onStepFinish to handleUIMessageStreamFinish() call in toUIMessageStream() Fixes vercel#12841
Contributor
Author
|
👋 Gentle ping — just checking if this is still on the radar for review. Happy to address any feedback or rebase if needed! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12841
The
onStepFinishcallback increateAgentUIStream,createAgentUIStreamResponse, andpipeAgentUIStreamToResponsewas typed asToolLoopAgentOnStepFinishCallback(LLM-level step result with token usage, finish reason, etc.), which is inconsistent with theUIMessageStreamOnStepFinishCallback(UI-levelmessages,isContinuation,responseMessage) used increateUIMessageStream.This makes it impossible to use
createAgentUIStreamfor the primary use-case of persisting intermediate messages during multi-step agent runs (as described in #12383).Changes
create-agent-ui-stream.ts: ChangedonStepFinishtype fromToolLoopAgentOnStepFinishCallbacktoUIMessageStreamOnStepFinishCallback; moved it fromagent.stream()toresult.toUIMessageStream()create-agent-ui-stream-response.ts: Same type changepipe-agent-ui-stream-to-response.ts: Same type changestream-text-result.ts: AddedonStepFinishtoUIMessageStreamOptionsso it threads throughtoUIMessageStream(),pipeUIMessageStreamToResponse(), andtoUIMessageStreamResponse()stream-text.ts: Destructured and passedonStepFinishtohandleUIMessageStreamFinish()intoUIMessageStream()Before / After
Before:
onStepFinishincreateAgentUIStreamreceivedOnStepFinishEventwith raw LLM details (usage tokens, finish reason, model response, etc.)After:
onStepFinishreceives{ messages, isContinuation, responseMessage }— the same shape ascreateUIMessageStream'sonStepFinish, making it easy to persist intermediate UI messages: