Repository navigation
Conversation
Author
|
Hi @supreme-gg-gg @dimetron, could you take a look at this PR when you get a chance? It's a related fix to #3289 in the same Anthropic adapter, so it may be easier to review them together. The CI workflows are also waiting for maintainer approval to run. Thanks! |
|
This pull request has been marked as stale because of no activity in the last 15 days. It will be closed in the next 5 days unless it is tagged "no stalebot" or other activity occurs. |
runAnthropicStreaming collected tool_use blocks in a map keyed by content-block index and assembled the final response by ranging over the map, so multiple parallel tool calls in one streamed response were emitted in randomized order. Iterate the indices in sorted order instead, matching the non-streaming path and the order the provider emitted the blocks. Signed-off-by: hairuiyang <hairuiyang@deeproute.ai>
halcyon-r
force-pushed
the
fix/anthropic-stream-tool-call-order
branch
from
November 10, 2026 11:59
f940e0c to
48d76b4
Compare
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.
runAnthropicStreamingcollectstool_useblocks in a map keyed bycontent-block index and assembles the final response by ranging over the map,
so when one streamed response carries multiple parallel tool calls, the
resulting parts — and the
FunctionCalls the agent loop executes — come out inrandomized order instead of the order the provider emitted them. Same class of
bug as #2988, which fixed randomized map iteration for Ollama argument order.
Tool results are matched by call ID, so nothing mispairs. The nondeterminism
shows up everywhere the parts travel: session history and replay, traces and UI
rendering, and any serial runner that executes the calls in part order. The
non-streaming path iterates
message.Contentin order, so streaming andnon-streaming disagreed for the same response shape.
order (
slices.Sorted(maps.Keys(...))), matching the non-streaming path.layout is unchanged.
Testing:
TestAnthropicStreamingKeepsParallelToolCallOrderstreams one textblock plus three tool calls (including one with no input deltas) and asserts
part order. It fails without the fix and loops 20× because map iteration order
is randomized and a single run can pass by chance.
go test ./adk/pkg/models/(run from
go/) passes andgo vetis clean.