Repository navigation
Fixes #3361 - #3362
Closed
Yeachan-Heo wants to merge 1 commit into
Closed
Fixes #3361#3362Yeachan-Heo wants to merge 1 commit into
Yeachan-Heo wants to merge 1 commit into
Conversation
Merge tool_result messages that follow an assistant message with multiple tool_use blocks, as required by the Anthropic Messages API contract. The API requires every tool_use block of an assistant message to be answered by tool_result blocks in the single message that immediately follows it. The prior implementation emitted one message per tool_result, so when an assistant turn issued multiple tool calls, the second and later results arrived one message too late and triggered HTTP 400. Convert_messages now uses fold() with absorb_tool_result_message to merge runs of adjacent tool-result-only messages, preserving the role and content of any message that follows a tool result. Fixes #3361
Contributor
Author
|
Closing as superseded: the parallel tool-result pairing fix for #3361 already landed on main in b8f93af (from #3360), with the regression test rust/crates/rusty-claude-cli/tests/parallel_tool_result_pairing.rs, and #3361 is closed by that commit. This branch would duplicate it. — |
|
这个修复很有必要:并行 tool_use 场景下 tool_result 必须全部放在紧随 assistant 消息之后的那条 user message 里,之前逐条拆分会被 Anthropic API 以 HTTP 400 拒绝。用 fold + absorb_tool_result_message 合并两个实现并补了回归测试,覆盖到位。 |
1 similar comment
|
这个修复很有必要:并行 tool_use 场景下 tool_result 必须全部放在紧随 assistant 消息之后的那条 user message 里,之前逐条拆分会被 Anthropic API 以 HTTP 400 拒绝。用 fold + absorb_tool_result_message 合并两个实现并补了回归测试,覆盖到位。 |
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.
Summary
Parallel tool calls in a single assistant message now have their results merged into one following user message, as required by the Anthropic Messages API.
Problem
When an assistant message contains multiple tool_use blocks (parallel tool calls), the convert_messages() function was emitting one user message per tool_result. The API requires all tool_results to arrive in the single message immediately following the assistant message, so the provider rejected requests with HTTP 400.
Example message sequence (before):
Solution
The convert_messages() function now uses fold() with absorb_tool_result_message() to merge consecutive tool-result-only messages. Both implementations (rusty-claude-cli and tools crate) are updated.
Example message sequence (after):
Testing
A new regression test (parallel_tool_result_pairing.rs) exercises the parallel tool call scenario against the mock Anthropic service and verifies the pairing contract.