Emit early progress frames for streaming tool calls#113
Open
adambalogh wants to merge 1 commit into
Open
Conversation
OpenAI/Anthropic tool calls are buffered server-side so the response signature can cover the complete arguments, and the full tool call was only flushed after the entire stream finished. For a large write_file call this meant the client received zero bytes for the whole generation (minutes): the UI showed no "writing file" activity and the connection sat idle long enough to trip read timeouts. Emit a lightweight progress frame as fragments arrive — carrying just the tool name/index, never the accumulating arguments — so the client's existing "preparing tool" indicator fires immediately and bytes keep flowing. The authoritative, argument-bearing tool call is still flushed once at the end of the stream ahead of the signed final frame, so the signed output and verification are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DKT5v2Ep7RU5Law5xh2L4i
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
Add support for emitting lightweight progress frames during streaming tool calls on buffered providers (OpenAI/Anthropic). This allows clients to display tool activity immediately (e.g., "writing file…") while the complete, argument-bearing tool call is still accumulated and flushed at the end of the stream for signing.
Problem
On buffered providers like OpenAI and Anthropic, tool calls are held until the stream ends so the signature can cover the complete arguments. This means clients receive no "tool starting" signal until generation finishes — a large
write_filecall can appear frozen for minutes while the file is being generated. Additionally, the lack of streaming bytes can cause read timeouts.Solution
_MockStreamChunktest helper to simulate LangChainAIMessageChunkobjects yielded bymodel.stream(), with support fortool_call_chunksandusage_metadatachat_controller.pywhen tool call chunks arrive with a name but incomplete arguments:index,id, andname— never the accumulating argumentstest_streaming_tool_call_emits_early_progress_frame) that:Implementation Details
The progress frame logic is gated by checking whether the tool call chunk has a
namefield but the accumulated tool call is incomplete. This ensures:https://claude.ai/code/session_01DKT5v2Ep7RU5Law5xh2L4i