You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Anthropic adapter sends tool_result blocks without tool_use_id, so multi-turn tool use fails #124
When it replays tool results, AnthropicProvider builds tool_result content blocks with an id field (src/providers/anthropic.ts, formatRequest, the message.toolResults mapping). The Claude Messages API requires tool_use_id there: the id of the tool_use block being answered. tool_use_id appears nowhere in src/.
From the code and Anthropic's docs, any multi-turn tool round trip through the Anthropic adapter should be rejected for every Claude model. This includes the factory tool loop (generateResponseWithTools), which builds toolResults messages. This has not been confirmed with a live API call; the existing tests mock fetch and never assert the field name.
Anthropic docs ("Handle tool calls", platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls, checked 2026-10-15): a tool_result block contains tool_use_id: The id of the tool use request this is a result for, plus optional content and is_error.
Related: Claude 5.x thinking blocks
Claude 5.x models think by default. Anthropic requires their thinking blocks to be passed back unmodified with tool results, and returns a 400 for edited or reordered ones. The adapter keeps only the joined reasoning text (LLMResponse.reasoning) and drops the blocks and their signatures. That is why #123 keeps the 5.x models explicit-only. Fixing both together is the prerequisite for making them routable again.
Proposed fix
Send tool_use_id: tr.id in tool_result blocks, and add a request-shape test, including through generateResponseWithTools.
Check the role and ordering rules: the tool_result blocks go first in a user message that immediately follows the assistant tool_use turn.
Design how thinking blocks (with signatures) survive a tool loop, for example opaque provider data on the assistant message that the adapter replays verbatim. Then lift explicitOnly from the Claude 5.x catalog entries.
Another adapter defect in the same path, found in the third review of #123:
When a tool fails, the factory tool loop sends the error in toolResults[].error with output: '' (src/factory.ts, around the toolResults.push calls in the tool loop). The Anthropic adapter builds the tool_result block from content: tr.output and only uses error to set is_error: true (src/providers/anthropic.ts, formatRequest). So Claude receives is_error: true with empty content, and the error text is lost.
Anthropic's docs ("Handle tool calls") show the error message going in content together with "is_error": true. The fix: when tr.error is set, send it as content (or append it to tr.output), and cover it in the same request-shape test as tool_use_id.
Status: the adapter fix is merged in #142 (tool_use_id, tool error text, and verbatim replay of tool-use turns through a new providerContent field) and ships in 1.25.0 (release PR #143). The Claude 5.x catalog entries are still explicitOnly; the three steps below are now tracked on #112.
Three adapter points to settle before the Claude 5.x models become routable (the first turned out to be handled already). All three came up in the #142 review and were checked against Anthropic's docs on 2026-11-06:
Forced tool use: already handled. (Corrected: an earlier version of this comment said it would fail.) Define tools → Forcing tool use: on Claude Opus 5.5, Claude Sonnet 5.5, Claude Fable 5.1 and Claude Mythos 5.1, tool_choiceany and tool return a 400; auto and none still work. Since 1.23.0 the adapter already throws ConfigurationError before the call when toolChoice is 'required' or a named function on the catalog's Fable 5.1, Opus 5.5 and Sonnet 5.5 entries (NO_FORCED_TOOL_CHOICE_MODELS, tested in model-refresh.test.ts); Mythos 5.1 is not in the catalog. Worth adding if it is. On models that do accept forced tool use (for example Claude Opus 5, Claude Haiku 5.5), a forced call skips thinking.
toolChoice: 'none' removes tools from the request.Thinking → Preserved thinking: on Claude 5.1 and later, a replayed thinking block is valid only while the top-level system, the tools and the earlier messages are unchanged. Dropping tools for a none turn invalidates the earlier turns' thinking. Anthropic supports tool_choice: {"type": "none"} with the tools kept, which keeps the prefix unchanged.
A fallback partway through a tool loop rebuilds the turn without its thinking. (Added after the final fix: Anthropic tool loops send tool_use_id, error text and thinking blocks (#124) #142 review.) If a loop starts on another provider and falls back to Anthropic, or moves between providers mid-loop, the earlier assistant tool-use turn has no Anthropic providerContent, so the adapter rebuilds it from content and toolCalls with no thinking block. Thinking → Thinking with tool use: adaptive mode, which Claude 5.x uses by default and is what the adapter gets since it sends no thinking parameter, does not require an assistant turn to start with a thinking block, so this is not a 400 (manual mode does enforce it). But "the API might strip thinking blocks that would create an invalid turn structure, or disable thinking when the conversation history is incompatible with thinking being enabled", silently, for that request. So the cost is lost reasoning for the rest of the turn, not an error. Before routing the 5.x models, decide whether a mid-loop fallback onto them is acceptable, should be kept off them, or should be surfaced (for example, by checking the response for thinking blocks).
Also worth deciding at that point: providerContent is set only on tool-use turns (the ones Anthropic requires back). Anthropic recommends passing thinking back on every turn, and Claude 5.x keeps prior turns' thinking in context, so final-answer thinking is currently not carried forward. This doesn't cause an error.
Fixed in 1.25.0 via #142 (released by #143): Anthropic tool_result blocks send tool_use_id; a failed tool's error is sent as content with is_error: true; tool-use turns are replayed verbatim, including signed thinking and redacted_thinking, through the new optional providerContent field. Groq, Cerebras and NVIDIA also send tool error text now.
The steps left before the Claude 5.x models become routable (keeping tools on toolChoice: 'none' turns, deciding how to handle a mid-loop fallback onto a thinking model, and lifting explicitOnly) are listed in the comment above and are now tracked on #112.
Activity
fix: correct release notes, restore streamed JSON brace, add factory …
stackbilt-admin commentedon Oct 15, 2026
Another adapter defect in the same path, found in the third review of #123:
When a tool fails, the factory tool loop sends the error in
toolResults[].errorwithoutput: ''(src/factory.ts, around thetoolResults.pushcalls in the tool loop). The Anthropic adapter builds thetool_resultblock fromcontent: tr.outputand only useserrorto setis_error: true(src/providers/anthropic.ts,formatRequest). So Claude receivesis_error: truewith empty content, and the error text is lost.Anthropic's docs ("Handle tool calls") show the error message going in
contenttogether with"is_error": true. The fix: whentr.erroris set, send it ascontent(or append it totr.output), and cover it in the same request-shape test astool_use_id.feat: refresh model list against vendor docs, Cloudflare first (v1.23…
docs: correct explicit-only reasons, test counts and validation evidence
docs: sync documentation after 1.23.0 (#125)
stackbilt-admin commentedon Nov 6, 2026
Status: the adapter fix is merged in #142 (
tool_use_id, tool error text, and verbatim replay of tool-use turns through a newproviderContentfield) and ships in 1.25.0 (release PR #143). The Claude 5.x catalog entries are stillexplicitOnly; the three steps below are now tracked on #112.Three adapter points to settle before the Claude 5.x models become routable (the first turned out to be handled already). All three came up in the #142 review and were checked against Anthropic's docs on 2026-11-06:
tool_choiceanyandtoolreturn a 400;autoandnonestill work. Since 1.23.0 the adapter already throwsConfigurationErrorbefore the call whentoolChoiceis'required'or a named function on the catalog's Fable 5.1, Opus 5.5 and Sonnet 5.5 entries (NO_FORCED_TOOL_CHOICE_MODELS, tested inmodel-refresh.test.ts); Mythos 5.1 is not in the catalog. Worth adding if it is. On models that do accept forced tool use (for example Claude Opus 5, Claude Haiku 5.5), a forced call skips thinking.toolChoice: 'none'removestoolsfrom the request. Thinking → Preserved thinking: on Claude 5.1 and later, a replayed thinking block is valid only while the top-levelsystem, thetoolsand the earlier messages are unchanged. Droppingtoolsfor anoneturn invalidates the earlier turns' thinking. Anthropic supportstool_choice: {"type": "none"}with the tools kept, which keeps the prefix unchanged.providerContent, so the adapter rebuilds it fromcontentandtoolCallswith no thinking block. Thinking → Thinking with tool use: adaptive mode, which Claude 5.x uses by default and is what the adapter gets since it sends nothinkingparameter, does not require an assistant turn to start with a thinking block, so this is not a 400 (manual mode does enforce it). But "the API might strip thinking blocks that would create an invalid turn structure, or disable thinking when the conversation history is incompatible with thinking being enabled", silently, for that request. So the cost is lost reasoning for the rest of the turn, not an error. Before routing the 5.x models, decide whether a mid-loop fallback onto them is acceptable, should be kept off them, or should be surfaced (for example, by checking the response for thinking blocks).Also worth deciding at that point:
providerContentis set only on tool-use turns (the ones Anthropic requires back). Anthropic recommends passing thinking back on every turn, and Claude 5.x keeps prior turns' thinking in context, so final-answer thinking is currently not carried forward. This doesn't cause an error.fix: address second PR #142 review
docs: add the mid-loop fallback item to the #124 routing steps
docs: address release PR #143 review
chore: release v1.25.0 (#143)
stackbilt-admin commentedon Nov 7, 2026
Fixed in 1.25.0 via #142 (released by #143): Anthropic
tool_resultblocks sendtool_use_id; a failed tool's error is sent ascontentwithis_error: true; tool-use turns are replayed verbatim, including signed thinking andredacted_thinking, through the new optionalproviderContentfield. Groq, Cerebras and NVIDIA also send tool error text now.The steps left before the Claude 5.x models become routable (keeping
toolsontoolChoice: 'none'turns, deciding how to handle a mid-loop fallback onto a thinking model, and liftingexplicitOnly) are listed in the comment above and are now tracked on #112.fix: Anthropic tool loops send tool_use_id, error text and thinking b…