Repository navigation
fix(providers): send parallel Anthropic tool results in one user message - #107
Draft
cursor[bot] wants to merge 1 commit into
Draft
cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
Claude often returns several tool_use blocks in one assistant turn. Each result was posted as its own user message, which the Messages API rejects, so the model never saw the tool output after the tools had already run. Co-authored-by: esadrianno <esadrianno@gmail.com>
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.
Bug and impact
When Claude returns two or more
tool_useblocks in one assistant turn (normal parallel tool use), the agent executes every tool and then sends each result as its ownusermessage. The Messages API accepts thosetool_resultblocks only inside the single following user message. The follow-up request is rejected (roles must alternate/ missingtool_resultfor the other ids), so the model never sees the tool output. The tools have already run, and the turn ends in an API error.Root cause
build_and_sendinsrc/providers/anthropic.cmapped eachtool_use_idmessage to a separate user message. The agent loop inagent.cstores one message per tool result.Fix
Consecutive tool-result messages are coalesced into one user message whose
contentarray holds atool_resultblock per call. A single tool result is unchanged.Validation
make test_anthropicpassed, includingtest_parallel_tool_results_share_one_user_message(two tool results become one user message with bothtool_use_ids, and the assistant message still carries bothtool_useblocks).src/providers/anthropic.calso compiles withoutSHELLCLAW_TEST.