Repository navigation
fix(anthropic): split parallel tool calls into alternating messages - #2090
Merged
oss-maintainer merged 2 commits intoJul 10, 2026
Merged
oss-maintainer merged 2 commits into
oss-maintainer merged 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes Anthropic request payload formatting when an assistant emits multiple parallel tool_use blocks by expanding them into Anthropic-required alternating assistant(tool_use) / user(tool_result) messages, addressing the 400 error described in #2077.
Changes:
- Add detection of “parallel tool-use batch + consecutive tool-result messages” and expand it into alternating Anthropic messages in
AnthropicMessageConverter. - Add a unit test covering conversion of two parallel tool calls into alternating messages.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic/src/main/java/io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverter.java | Adds logic to detect completed parallel tool-call batches and rewrite them into alternating assistant/user messages for Anthropic compatibility. |
| agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-anthropic/src/test/java/io/agentscope/extensions/model/anthropic/formatter/AnthropicMessageConverterTest.java | Adds a regression test validating the alternating-message expansion behavior. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
oss-maintainer
approved these changes
Jul 10, 2026
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
Close #2077
Summary
Fixes Anthropic message formatting for parallel tool calls.
When a single assistant message contains multiple
ToolUseBlocks and the following messages contain the correspondingToolResultBlocks, Anthropic requires the request payload to alternate as:assistant(tool_use_1) -> user(tool_result_1) -> assistant(tool_use_2) -> user(tool_result_2)
This PR updates
AnthropicMessageConverterto detect completed parallel tool-call batches and expand them into Anthropic-compatible alternating messages before sending the request.Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)