Patch Changes
-
#11603
fec9cd8Thanks @thushanth-bengre-langchain! - fix(core): build streamingllmOutput.tokenUsagefrom the fully-accumulated chunk instead of whichever individual chunk'susage_metadataarrived lastAffects both core streaming paths —
.stream()/.streamEvents()(_streamIterator) and.invoke()/.generate()when a streaming-preferring callback is attached (_generateWithCache'shasStreamingHandlerbranch). Previously,llmOutput.tokenUsagewas overwritten by each chunk in turn, so only the last chunk carryingusage_metadatawon — correct for providers that emit one cumulative total on a final chunk, but wrong for providers (e.g.@langchain/google,@langchain/anthropic) that emitusage_metadataas a per-chunk delta across multiple chunks, where the values must be summed.Note for provider authors: this assumes each streamed chunk's
usage_metadatais either a per-chunk delta or appears only on a single final chunk. A provider that instead repeats a cumulative total on every chunk will now see it summed (and inflated) inllmOutput.tokenUsage, matching the existing behavior of the correctly-workingmessage.usage_metadatafield.Also fixes
@langchain/google'sinvoke({streaming: true})path (no streaming-preferring callback attached), wherellmOutputwas never populated at all. -
#11590
ffebdc2Thanks @thushanth-bengre-langchain! - Fix OpenAI Responses API replay under Zero Data Retention when a response contains more than one reasoning item, for both v0 and v1. In v0, the default replay path now reusesresponse_metadata.outputdirectly, preserving every reasoning item'sid/encrypted_contentin original order. In v1,AIMessage.contentBlocks(outputVersion: "v1") is fixed the same way.additional_kwargs.reasoningis unchanged.