fix(anthropic): send parallel tool results in one user message - #52
Merged
Merged
Conversation
Each OpenAI `tool` message was converted to its own user message, so a turn with parallel calls produced consecutive user messages. Anthropic merges them, but llm-hub translating to deepseek-flash rejects it: "An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'" (Forge run r-20260929-110952-e081, cs_encoded_word, turn 2). Fold consecutive tool-result-only user messages into one, the documented shape. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Problem
_to_anthropic_msgturns each OpenAItoolmessage into its ownusermessage, so parallel tool calls produce consecutive user messages with onetool_resulteach. Anthropic merges them, but gateways translating the Messages API to another backend don't: llm-hub → deepseek-flash returned 400 "An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'" and the ApodexHarness episode ended withllm_errorat turn 2 (Forger-20260929-110952-e081).Fix
_merge_tool_resultsfolds consecutive tool-result-only user messages into one (Anthropic's documented shape). Transient messages (runtime addendum) are never merged, so the rolling cache breakpoint from #48 still lands on the merged tool-result message.Tests
tool_resultblocks, addendum stays separate.Full suite 1612 passed; ruff + pyright clean. Fragment added.
🤖 Generated with Claude Code