May 19, 2026
Aggregating Anthropic Streams in LangChain.js
This happens to be my first contribution to LangChain.
I chose the TypeScript path because I want to stay deeply rooted in the web ecosystem while engineering with AI tools, learning about agents, and understanding orchestration systems at a lower level.
The problem here was to prevent an interpretive failure introduced by a newer update that enforced stricter validation on streaming data frames.
The data stream is processed through @langchain/core, which acts as the foundational orchestration layer for the broader LangChain ecosystem inside the local Node.js runtime.
In v1.1.46, a stricter security/type guard was introduced.
The initial stream frame emits JSON with:
{
"type": "tool_use"
}Subsequent delta frames emit:
{
"type": "input_json_delta"
}The issue originates in getMergeableTypeBase().
The function normalizes frame types by truncating the _delta suffix. As a result:
input_json_delta → input_jsonThat normalized value is then compared against "tool_use".
Because of the stricter validation introduced in the newer pull request, this mismatch gets flagged and throws an OUTPUT_PARSING_FAILURE.
My fix was to update getMergeableTypeBase() so that both:
input_json
input_json_deltacorrectly map to:
"tool_use"I also integrated aggregation tests for this logic.
Initially, I added the tests inside the @langchain/anthropic provider package.
After review feedback from Bromann, who works on agentic workflows at LangChain, I moved the tests into the LangChain core workspace instead.
I also handled formatting and styling updates to ensure the CI formatting checks passed successfully.
Link To Issue ↗