fix(streaming): fire BetaInputJsonEvent for server_tool_use blocks#1446
Open
abhicris wants to merge 1 commit intoanthropics:mainfrom
Open
fix(streaming): fire BetaInputJsonEvent for server_tool_use blocks#1446abhicris wants to merge 1 commit intoanthropics:mainfrom
abhicris wants to merge 1 commit intoanthropics:mainfrom
Conversation
…loses anthropics#1421) `lib/streaming/_beta_messages.py` fired `BetaInputJsonEvent` for `tool_use` and `mcp_tool_use` content blocks but not for `server_tool_use`, even though the API streams `input_json_delta` events for server-side tools the same way. This was inconsistent with the accumulator's own `TRACKS_TOOL_INPUT` tuple which already includes `BetaServerToolUseBlock` — so the SDK accumulates streamed input into `content_block.input` correctly, but never fires the parsed event to consumers. Forces consumers to bypass `BetaInputJsonEvent` and match on the raw `BetaRawContentBlockDeltaEvent` with a `BetaInputJSONDelta` delta. Add `"server_tool_use"` to the content-block type check so the parsed event fires for server-side tool input streaming (e.g. `tool_search_tool_regex`, `web_search`).
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.
Closes #1421.
Bug
`lib/streaming/_beta_messages.py` fires `BetaInputJsonEvent` for `tool_use` and `mcp_tool_use` content blocks but not for `server_tool_use`, even though the API streams `input_json_delta` events for server-side tools the same way.
This was inconsistent with the accumulator's own `TRACKS_TOOL_INPUT` tuple in the same file, which does include `BetaServerToolUseBlock` — so the SDK accumulates the streamed input into `content_block.input` correctly, but never fires the parsed event to consumers. Forces consumers to bypass `BetaInputJsonEvent` and match on the raw `BetaRawContentBlockDeltaEvent` with a `BetaInputJSONDelta` delta.
Fix
Add `"server_tool_use"` to the content-block type check on line 368:
```diff
elif event.delta.type == "input_json_delta":
```
(Plus a comment explaining the consistency with `TRACKS_TOOL_INPUT`.)
`+8 / -1`. Affects only the parsed event surface — the accumulator's state already tracks server_tool_use correctly. Now `tool_search_tool_regex` / `web_search` / future server-side tools' input streams will surface as `BetaInputJsonEvent` to consumers using the stream helpers.
Contributed by kcolbchain.