Repository navigation
fix: Anthropic tool loops send tool_use_id, error text and thinking blocks (#124) - #142
Merged
Merged
Conversation
…locks (#124) - tool_result blocks send tool_use_id instead of id. - A failed tool's error message goes in content with is_error: true. - Rebuilt assistant tool-call turns keep their text before tool_use. - New LLMResponse/LLMMessage.providerContent ({ provider, blocks }): an Anthropic response that calls tools carries the turn's content blocks (thinking with signatures, redacted_thinking, text, tool_use) in order, and the Anthropic provider replays them unchanged, as Anthropic requires for tool-use turns. generateResponseWithTools copies it; other providers ignore it; malformed Anthropic content throws ConfigurationError. - Response schema knows redacted_thinking and the thinking signature; canonical normalization and the response cache carry and validate the new field. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Rebuilt assistant turns skip whitespace-only text (not a valid text block). - generateResponseWithTools reports non-Error throws and empty-message errors as tool errors instead of empty successes. - Shared isValidProviderContent: the Anthropic replay and the response cache now accept the same values (non-empty, typed blocks, no user-turn block types such as tool_result or image for Anthropic). - Canonical normalization deep-copies providerContent. - Tests: whitespace text, streaming replay, user-turn/image blocks, silent tool failures, mid-loop fallback in both directions, cache empty-array rejection, canonical deep copy. - README/CHANGELOG: tool-use-turn scope and error wording; checkpoint notes #142 and the remaining Claude 5.x gaps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Groq, Cerebras and NVIDIA send a failed tool's error as { output, error }
JSON, like OpenAI (shared openAIToolResultContent helper).
- Tool loop takes error text from any thrown object with a non-blank
message; whitespace-only messages get the generic text.
- providerContent is captured only when every tool_use survives
validation, and not on JSON-prefill responses; replay requires complete
tool_use blocks and rebuilds the turn when tool_use ids differ from
toolCalls.
- copyProviderContent throws ConfigurationError for non-JSON blocks.
- Tests for each, plus a three-round loop and factory cache hit/miss.
- README/CHANGELOG/checkpoint wording matches the code; the checkpoint no
longer lists done #124 work or forced toolChoice as open.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Anthropic content needs signed thinking and redacted_thinking data: unsigned turns aren't captured and are rejected on replay. - Replay shape check moved to validateRequest, so a caller mistake isn't recorded as a provider failure. - Warn when an assistant message's content differs from the providerContent being sent; README documents that edits to content are not sent. - The response cache treats an Anthropic tool-call entry without providerContent (written by 1.24.x) as a miss. - Tool loop guards a throwing message getter. - Tests for each, plus provider-prefix cache hints leaving replayed blocks untouched; reset the fetch mock between tests so failures can't cascade. - README/CHANGELOG/checkpoint updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Response cache keys move to llmp:v3:, so pre-1.25 entries without providerContent aren't reused; drop the cache rule that also blocked writes of tool-call responses without providerContent. - Warn whenever replayed content differs from the message's content, including blank content; a null content no longer throws. - Document that the shape check runs before the tool_use id check, and narrow "not a provider failure" to provider metrics and the breaker. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Replayed Anthropic thinking blocks need string thinking text (empty is fine) and text blocks need string text, so a hand-built or corrupted block is rejected before dispatch instead of failing at the provider. - Test that a tool-call response with providerContent is written to the response cache and then served from it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The rebuild path's comment no longer calls whitespace-only text an invalid block; it says the rebuilt turn leaves it out and replay keeps every block as returned. - copyProviderContent throws only for BigInt and circular references; say so, and describe how other non-JSON values are converted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 7, 2026
Merged
stackbilt-admin
pushed a commit
that referenced
this pull request
Nov 7, 2026
- README: the Claude 5.x models stay explicitOnly until the remaining routing steps tracked on #112 are done (not "until #124"). - CHANGELOG: the llmp:v3: cache-key change moves to Changed; the providerContent entry cites #142. - Checkpoint: the publish workflow re-run is future tense; clearer wording for the #112 routing steps. Co-Authored-By: Claude Opus 5.5 <[email protected]>
stackbilt-admin
added a commit
that referenced
this pull request
Nov 7, 2026
Anthropic tool loops (#124, #142): tool_use_id, tool error text and verbatim replay of tool-use turns via the new providerContent field; tool error text on Groq, Cerebras and NVIDIA. Bumps package.json, package-lock.json and src/version.ts to 1.25.0, adds the CHANGELOG section (the llmp:v3: cache-key change under Changed, with an upgrade note), points the README Claude 5.x explicitOnly note at the routing steps now tracked on #112, and refreshes the issue-sweep checkpoint. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #124. Additive, so it targets a minor release (1.25.0).
Multi-turn tool use through the Anthropic provider, including
generateResponseWithTools(), was rejected by the Messages API on every Claude model. Anthropic docs checked 2026-11-06: Handle tool calls, Define tools and Thinking (Preserving thinking blocks, Redacted thinking, Preserved thinking).Fixed
tool_resultblocks sendtool_use_id; they sentid.contentwithis_error: true, after any partial output; it was sent as empty content.contentandtoolCallskeeps its text before thetool_useblocks (whitespace-only text is left out); the text was dropped.{ "output", "error" }JSON in the tool message, the format OpenAI already used (shared helpersrc/utils/tool-results.ts). They sent only the output, so failures reached the model as empty successes.generateResponseWithTools()no longer reports a failed tool as an empty success when it throws something other than anErrorwith a message: a thrown string, or any object with a non-blankmessage, is the error text; anything else getsTool '<name>' failed without an error message.Added:
providerContentClaude 5.x models think by default. Within a tool-use turn, Anthropic requires the thinking blocks (including
redacted_thinking) to be sent back complete, unmodified and in order; on 5.1+ models a block is valid only if everything before it is unchanged. So the turn is replayed verbatim:LLMResponse.providerContentandLLMMessage.providerContent, typeProviderContent({ provider, blocks }).tool_useblock fails validation (the call is dropped fromtoolCalls), when athinkingblock has no signature, and on JSON-prefill responses; those turns are rebuilt instead.generateResponseWithTools()copies the field onto the assistant message, and the Anthropic provider sends it in place ofcontentandtoolCalls. An edit made only tocontentis therefore not sent; the provider logs a warning whencontentdiffers from the replayed text (blank or missingcontentincluded), and the README says so. Other providers ignore the field; a fallback partway through a loop rebuilds the turn, as before.src/utils/provider-content.ts, shared by replay and the response cache):tool_result,image,document,search_result);tool_useblock has an id, name and input;thinkingblock has stringthinkingtext and a signature, everyredacted_thinkingblock has data, and everytextblock has stringtext;ConfigurationErrorinvalidateRequest, before dispatch, so it isn't recorded in the provider's metrics or circuit breaker (the factory still logs it, firesonRequestErrorand reports the failed attempt); a cache entry that fails is treated as a miss;tool_useids differ from the message'stoolCalls, the turn is rebuilt; the shape is checked first, so malformed content throws even then.llmp:v2:tollmp:v3:, so entries written by 1.24.x or earlier, which lackproviderContent, are not reused (the cache starts cold after upgrading). Tool-call responses withoutproviderContentare still cached.redacted_thinkingand the thinkingsignature. Canonical normalization deep-copies the field as JSON, and throwsConfigurationErrorfor blocks with a BigInt or a circular reference.Tests
src/__tests__/anthropic-tool-loop.test.ts, 57 tests asserting exact request bodies:tool_use_id, and error text with and without partial output;tool_use, unsigned thinking and JSON prefill;contentwas edited, blank or null butproviderContentwasn't;provider-prefixcache hints leaving replayed blocks untouched;generateResponseWithToolsloops;messagegetter;providerContent;Each review round's new tests were also run against the code from before that round's fixes; the ones covering a fix failed there.
Local: typecheck, 894 tests, build, package smoke test, worker import smoke test.
Not in this PR
explicitOnly. Before making them routable,toolChoice: 'none'should keeptoolsin the request, so earlier thinking stays valid on 5.1+ (see the comment on Anthropic adapter sends tool_result blocks without tool_use_id, so multi-turn tool use fails #124). ForcedtoolChoiceis already rejected before the call on Fable 5.1, Opus 5.5 and Sonnet 5.5.providerContentis set only on tool-use turns, so thinking from final answers isn't carried into later turns. That's allowed, and it doesn't cause an error.fetch.providerContent(the tool loop doesn't stream).🤖 Generated with Claude Code