Repository navigation
fix(anthropic): record streamed tool calls and avoid corrupting response text - #8054
Open
ansh-rohilla wants to merge 1 commit into
Open
ansh-rohilla wants to merge 1 commit into
ansh-rohilla wants to merge 1 commit into
Conversation
…nse text Streamed Anthropic tool_use responses accumulated input_json_delta chunks into the same content_blocks list as text, causing gen_ai.response.text to be polluted with raw tool JSON and gen_ai.response.tool_calls to never be set. Track content blocks by index and event type across content_block_start, content_block_delta, and content_block_stop, parse accumulated tool JSON deltas into tool input on completion, and forward structured blocks to _set_output_data. Fixes getsentry#8050
This branch has not been deployed
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.
Description
When streaming Anthropic responses that include tool calls (
tool_use),input_json_deltachunks were being appended to the samecontent_blockslist as text deltas. This resulted in two bugs:gen_ai.response.textwas corrupted with raw tool JSON (e.g.{"location": "San Francisco, CA"}).gen_ai.response.tool_callswas never populated for streamed responses.This PR addresses this by:
content_block_start,content_block_delta, andcontent_block_stopin_collect_ai_data().tool_usemetadata on block start and accumulating JSON fragments in_partial_json.inputdictionary oncontent_block_stop._set_output_data()in_set_streaming_output_data(), which properly populatesgen_ai.response.tool_callsand keepsgen_ai.response.textclean.gen_ai.response.tool_callsand adding tests for mixed text + tool use streams and block lifecycle events.Issues