Fix buffering for server_tool_use input in streamed responses#558
Open
CodeWrap wants to merge 1 commit into
Open
Fix buffering for server_tool_use input in streamed responses#558CodeWrap wants to merge 1 commit into
CodeWrap wants to merge 1 commit into
Conversation
`server_tool_use` blocks were dropping `input_json_delta`, leaving completed `ProviderToolEvent` instances and `$responseContent` empty. Buffer server tool input deltas the same way as client `tool_use` and add a streaming regression test that assembles input from deltas.
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.
HandlesTextStreamingwas only bufferinginput_json_deltafor clienttool_useblocks.That meant
server_tool_useblocks likeweb_searchandadvisorcould stream input deltas, but the SDK would drop them. By the time the completedProviderToolEventfired, and by the time the block was written into$responseContent, the tool input was still empty.This change adds a parallel
$serverToolInputBuffersaccumulator forserver_tool_useblocks and assembles the final input before emitting the completedProviderToolEvent, following the same pattern we already use for client tools via$pendingToolCalls.I also used
$currentBlockIndexas the fallback index instead ofcount($responseContent) - 1, which is safer while blocks are still being streamed.Includes a streaming test that feeds a
server_tool_useblock with multipleinput_json_deltachunks and asserts that the completedProviderToolEventcontains the fully assembled input.I ran into this while trying to capture streamed
web_searchqueries: theProviderToolEventwas always arriving with empty input.