fix(combo/fusion): flatten Anthropic style tool messages in panel calls#1910
Open
warelik wants to merge 1 commit into
Open
fix(combo/fusion): flatten Anthropic style tool messages in panel calls#1910warelik wants to merge 1 commit into
warelik wants to merge 1 commit into
Conversation
Anthropic format places tool_use and tool_result blocks in the content array of assistant and user messages respectively. This patch updates flattenToolHistory to recognize and flatten them into prose for panel calls.
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
This is a follow-up to #1859. When using the
fusionstrategy with an Anthropic-compatible client (e.g., Claude Code, or other Anthropic-compatible integrations pointing to/v1/messages), the client sends previous tool usage in the Anthropic format, where tool invocations and results are nested inside the messagecontentarray as blocks (type: "tool_use"andtype: "tool_result").The
flattenToolHistoryhelper only recognized OpenAI-style tool calls (msg.role === "tool"andmsg.tool_callsarray on assistant messages). As a result, Anthropic's tool blocks were left unmodified, and since thetoolsdefinitions are stripped from the panel calls (as implemented in #1859), the panel expert models would receive structured tool history without schemas, causing them to fail or misbehave (leading to empty responses and 503 errors).This PR extends
flattenToolHistoryto correctly recognize and flatten Anthropic-style tool blocks within thecontentarray into prose text, keeping panel expert execution robust and independent of the client's API format.Changes
open-sse/services/combo.js— UpdateflattenToolHistoryto inspectcontentarrays fortool_useandtool_resultblocks. If present, extract any interleaved text, join the tool names/results into plain text, and format them using the predefinedTOOL_CALL_PREFIXandTOOL_RESULT_PREFIXstrings.tests/unit/combo-fusion.test.js— Add a new unit testflattens Anthropic-style tool_use and tool_result blocks in arraysverifying the correct extraction and formatting of both block types.All 8 unit tests pass successfully.