fix(core): allow input_json_delta aggregation for anthropic tool_use …#10923
fix(core): allow input_json_delta aggregation for anthropic tool_use …#10923Arjun Shenoy (noishey) wants to merge 8 commits into
Conversation
🦋 Changeset detectedLatest commit: 579a400 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thanks for the PR! Do you think we can add unit tests, e.g. in the Anthropic provider package verifying this works? |
|
Absolutely! I can definitely add some unit tests for this. I'll update the PR as soon as they are ready! |
4f27524 to
55aab9c
Compare
Christian Bromann (christian-bromann)
left a comment
There was a problem hiding this comment.
one minor nit
| }); | ||
| }); | ||
|
|
||
| test("should successfully aggregate tool_use and input_json_delta chunks via .concat()", async () => { |
There was a problem hiding this comment.
It seems like this test doesn't use any primitives exported in the Anthropic package, so can we move it into the core workspace?
55aab9c to
91a57ae
Compare
91a57ae to
57287bb
Compare
| }); | ||
| }); | ||
|
|
||
| test("should successfully aggregate tool_use and input_json_delta chunks via .concat()", async () => { |
There was a problem hiding this comment.
Can we move this test into @langchain/core?
Description
Fixes a critical regression introduced in
v1.1.46that breakswithStructuredOutput().stream()for Anthropic models.Root Cause
Anthropic's streaming protocol uses an asymmetric naming convention during tool execution:
type: "tool_use"type: "input_json_delta"getMergeableTypeBase()normalizesinput_json_deltatoinput_json. Because"input_json" !== "tool_use", the strict nominal type check introduced in PR #10790 flags this as a type mismatch and rejects the merge, throwing anOUTPUT_PARSING_FAILURE.Solution
Explicitly map
input_json_deltaandinput_jsonto return"tool_use"withingetMergeableTypeBase(). This bridges the structural protocol gap, satisfies the type invariance check, and allows streamed JSON fragments to aggregate seamlessly.Related Issues
Closes #10907
Author: @noishey