Merge streaming tool call deltas by index in OpenAiChatModel#6381
Open
jewoodev wants to merge 1 commit into
Open
Merge streaming tool call deltas by index in OpenAiChatModel#6381jewoodev wants to merge 1 commit into
OpenAiChatModel#6381jewoodev wants to merge 1 commit into
Conversation
The streaming chunk aggregation detects the start of a new tool call by the presence of the delta id field. OpenAI omits id on continuation deltas, but some OpenAI-compatible endpoints (e.g. DeepSeek) send an empty string instead, so every continuation delta surfaced as a separate tool call with fragmented arguments and tool execution failed. Key the merge on the delta's required index field instead, which the streaming API defines for correlating tool call deltas and which the aggregation used until 2.0.0-M8. This also lifts the one-tool-call-per- chunk limitation and merges parallel tool call deltas correctly. Fixes spring-projectsgh-6374 Signed-off-by: jewoodev <jewoos15@naver.com>
d1d69a0 to
6c04458
Compare
Contributor
Author
|
Rebased onto main to resolve a conflict with #6365. #6365 changed The streaming test added in #6365 ( |
This was referenced Jun 11, 2026
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
Streaming tool calls through
OpenAiChatModelagainst OpenAI-compatible endpoints such as DeepSeek are broken since 2.0.0-RC1: every argument fragment surfaces as a separateToolCallwith an empty id and name, so tool execution receives null or empty arguments.ChunkMerger.mergeDeltastreats a delta as the start of a new tool call whentoolCall.id().isPresent(). OpenAI omitsidon continuation deltas, but DeepSeek-style endpoints send"id": "", which is present, so each fragment is appended as a new tool call instead of being concatenated into the previous one. Up to 2.0.0-M8 the aggregation keyed tool call builders bychoice.index() + "-" + toolCall.index()and was not affected; the behavior changed when 12f5cbe (#6288) replaced that aggregation, and d72057c later moved the logic intoChunkMergerunchanged.This change keys the merge on the delta's required
indexfield, which is what the streaming API defines for correlating tool call deltas. It also lifts the previous one-tool-call-per-chunkAssertand merges parallel tool call deltas correctly when fragments interleave across indexes.Test
ChunkMergeris now package-private (was private) for direct unit testing. The new tests cover OpenAI-style absent continuation ids, DeepSeek-style empty-string ids (the gh-6374 reproduction), parallel tool calls, and multiple tool call deltas in a single chunk. Verified with./mvnw -pl models/spring-ai-openai package.Relation to existing work
#6369 fixes the empty-id continuation case narrowly for #4790. This PR takes the index-keyed path in the current 2.0
OpenAiChatModel.ChunkMerger, which also covers omitted continuation ids, empty-string continuation ids, parallel tool-call indexes, and multiple tool-call deltas in one chunk. Older PRs such as #5973/#4794 target the previous helper-layer code path, while this PR is scoped to the currentChunkMergerimplementation.Fixes gh-6374