feat(claude-agent-sdk): opt-in multi-block tool-result concatenation - #2637
Open
boyuan-fh wants to merge 1 commit into
Open
feat(claude-agent-sdk): opt-in multi-block tool-result concatenation#2637boyuan-fh wants to merge 1 commit into
boyuan-fh wants to merge 1 commit into
Conversation
buildAguiToolMessage reads only content[0], dropping later blocks for multi-block tool results. Add a concatenateToolResultBlocks config option (default false) that opts into iterating all blocks; the default preserves the existing content[0] behavior exactly. When enabled, text blocks join with \n and mixed text+non-text content falls back to JSON.stringify(content) so non-text blocks (e.g. images) are not dropped. Fixes #<issue>
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.
Fixes #2632
Summary
buildAguiToolMessagereads onlycontent[0], silently dropping everythingafter the first block for tools returning multiple content blocks. Rather than
changing the default behavior, this adds a
concatenateToolResultBlocksconfigoption (default
false) so callers can opt in.concatenateToolResultBlocks: false(default): exactly the currentcontent[0]-only behavior. No behavioral change for existing consumers.concatenateToolResultBlocks: true: iterates all content blocks. Textblocks are joined with
\n; mixed content (text + non-text blocks) fallsback to
JSON.stringify(content)to avoid silently dropping non-text blockslike images.
The JSON round-trip (
JSON.stringify(JSON.parse(text))) is preserved in bothpaths for parity with the Python sibling adapter. Whether to remove it is an
open question (happy to drop the round-trip in favor of verbatim pass-through if you prefer).
Config option
concatenateToolResultBlocksbooleanfalseClaudeAgentAdapterConfiginsrc/types.tsadapter.tsreadsthis.config.concatenateToolResultBlocksand passes it as the third argument to
buildAguiToolMessage(toolUseId, resultContent, concatenate).Test plan
New
src/utils.buildAguiToolMessage.test.tswith 16 cases in two groups:Shared edge cases (independent of flag):
"[]"JSON.stringifyidformat (${toolUseId}-result)Default (concatenate disabled):
JSON.stringify(content)Opt-in (concatenate enabled):
\nJSON.stringify(content)JSON.stringify(content)[image, text]): image survives