Skip to content

fix(providers): send parallel Anthropic tool results in one user message - #107

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-e2ab
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-e2ab

Conversation

@cursor

@cursor cursor Bot commented Oct 1, 2026

Copy link
Copy Markdown

Bug and impact

When Claude returns two or more tool_use blocks in one assistant turn (normal parallel tool use), the agent executes every tool and then sends each result as its own user message. The Messages API accepts those tool_result blocks only inside the single following user message. The follow-up request is rejected (roles must alternate / missing tool_result for 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_send in src/providers/anthropic.c mapped each tool_use_id message to a separate user message. The agent loop in agent.c stores one message per tool result.

Fix

Consecutive tool-result messages are coalesced into one user message whose content array holds a tool_result block per call. A single tool result is unchanged.

Validation

make test_anthropic passed, including test_parallel_tool_results_share_one_user_message (two tool results become one user message with both tool_use_ids, and the assistant message still carries both tool_use blocks). src/providers/anthropic.c also compiles without SHELLCLAW_TEST.

Open in Web聽View Automation聽

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant