Skip to content

fix(combo/fusion): flatten Anthropic style tool messages in panel calls#1910

Open
warelik wants to merge 1 commit into
decolua:masterfrom
warelik:fix/fusion-combo-anthropic-tools
Open

fix(combo/fusion): flatten Anthropic style tool messages in panel calls#1910
warelik wants to merge 1 commit into
decolua:masterfrom
warelik:fix/fusion-combo-anthropic-tools

Conversation

@warelik

@warelik warelik commented Jun 19, 2026

Copy link
Copy Markdown

Summary

This is a follow-up to #1859. When using the fusion strategy 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 message content array as blocks (type: "tool_use" and type: "tool_result").

The flattenToolHistory helper only recognized OpenAI-style tool calls (msg.role === "tool" and msg.tool_calls array on assistant messages). As a result, Anthropic's tool blocks were left unmodified, and since the tools definitions 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 flattenToolHistory to correctly recognize and flatten Anthropic-style tool blocks within the content array into prose text, keeping panel expert execution robust and independent of the client's API format.

Changes

  1. open-sse/services/combo.js — Update flattenToolHistory to inspect content arrays for tool_use and tool_result blocks. If present, extract any interleaved text, join the tool names/results into plain text, and format them using the predefined TOOL_CALL_PREFIX and TOOL_RESULT_PREFIX strings.

  2. tests/unit/combo-fusion.test.js — Add a new unit test flattens Anthropic-style tool_use and tool_result blocks in arrays verifying the correct extraction and formatting of both block types.

All 8 unit tests pass successfully.

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.
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