Skip to content

Fix buffering for server_tool_use input in streamed responses#558

Open
CodeWrap wants to merge 1 commit into
laravel:0.xfrom
CodeWrap:fix/server-tool-input-buffering
Open

Fix buffering for server_tool_use input in streamed responses#558
CodeWrap wants to merge 1 commit into
laravel:0.xfrom
CodeWrap:fix/server-tool-input-buffering

Conversation

@CodeWrap
Copy link
Copy Markdown
Contributor

HandlesTextStreaming was only buffering input_json_delta for client tool_use blocks.

That meant server_tool_use blocks like web_search and advisor could stream input deltas, but the SDK would drop them. By the time the completed ProviderToolEvent fired, and by the time the block was written into $responseContent, the tool input was still empty.

This change adds a parallel $serverToolInputBuffers accumulator for server_tool_use blocks and assembles the final input before emitting the completed ProviderToolEvent, following the same pattern we already use for client tools via $pendingToolCalls.

I also used $currentBlockIndex as the fallback index instead of count($responseContent) - 1, which is safer while blocks are still being streamed.

Includes a streaming test that feeds a server_tool_use block with multiple input_json_delta chunks and asserts that the completed ProviderToolEvent contains the fully assembled input.

I ran into this while trying to capture streamed web_search queries: the ProviderToolEvent was always arriving with empty input.

`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.
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