feat(core): new event streaming#10772
Conversation
🦋 Changeset detectedLatest commit: a4840ac The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
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 |
09f02e8 to
d94e7a9
Compare
Hunter Lovell (hntrl)
left a comment
There was a problem hiding this comment.
For right now I can speak to the public api surface -- I'm fine largely trusting the design decisions behind transformers (though I'm excited to see the readout as someone largely observing from arms length)
- Middleware isn't a protocol event right, it's just a projection of node events that we get from inside of a graph?
- on chat model events
- I think we need to keep the
deltasemantics. Right now we extrapolate by just using PartialContentBlock in the delta type, but I think we'd benefit by making these explicit if I'm just thinking about it from a "completions first" perspective- Like its not abundantly clear to me that we'd do special handling for named
text+reasoningfields (assuming that these come across as token chunks) vs. this third delta type - A lot of this is predicated on us having the same idea of how delta merging works which I know was very in flux
- Like its not abundantly clear to me that we'd do special handling for named
- Hopefully we can do away with
tool_call_chunkandserver_tool_call_chunkif we stick to the three delta types and just have tool call chunks be handled by a merge function that just goes one layer deep when we get that third delta type?
- I think we need to keep the
Correct, both |
Kept delta semantics, see langchain-ai/agent-protocol#78 |
…ol-call-delta, block-delta) - Replace generic DeepPartialContentBlock on delta events with a discriminated union of typed deltas - text-delta/reasoning-delta: append semantics - tool-call-delta: append args, set id/name - block-delta: overwrite semantics for catch-all - Remove accumulated content from delta events (sub-streams now read directly from typed deltas) - Rename chatModelStream() -> streamV2() - Extract bridge logic into compat.ts - Remove createChatModelStream factory (use new ChatModelStream) - Remove type guard functions from event.ts
- Remove ToolCallDelta type; tool call args now use block-delta with accumulated snapshot (adapter accumulates internally) - Rename block-delta.content -> block-delta.fields to avoid confusion with content on start/finish events - Three delta types remain: text-delta (append), reasoning-delta (append), block-delta (overwrite)
Create new-guests-yell.md actually use __native flag more tests and details formatting better fix fix: parse tool call input better middleware typing format add integration tests use eventlog for native stream transformer format keep stream transformer in type bag cr update langgraph update langgraph
d44cb96 to
9a9b4c2
Compare
📦 Dev Release PublishedA dev release has been published for this PR!
Install: npm i @langchain/core@1.1.43-dev-1777615538778 @langchain/perplexity@0.2.0-dev-1777615538778 langchain@1.4.0-dev-1777615538778 --save-exact |
Hunter Lovell (hntrl)
left a comment
There was a problem hiding this comment.
can we split up the langchain-core/langchain changes so we don't have to rely on a dev release?
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @langchain/perplexity@0.2.0 ### Minor Changes - [#10781](#10781) [`1f76917`](1f76917) Thanks [@jliounis](https://github.com/jliounis)! - feat(perplexity): add Perplexity Search retriever (`PerplexitySearchRetriever`) and tool (`PerplexitySearchResults`) ## @langchain/core@1.1.43 ### Patch Changes - [#10814](#10814) [`dfec1b7`](dfec1b7) Thanks [@hntrl](https://github.com/hntrl)! - fix(google): restore structured output parsing with includeRaw and reasoning blocks Ensure structured output parsers read `BaseMessage` text content when `includeRaw: true`, so responses that include reasoning/thought blocks plus JSON text continue to parse correctly. - [#10772](#10772) [`1ba7131`](1ba7131) Thanks [@christian-bromann](https://github.com/christian-bromann)! - chore(core): new stream primitives ## @langchain/google-common@2.1.30 ### Patch Changes - [#10814](#10814) [`dfec1b7`](dfec1b7) Thanks [@hntrl](https://github.com/hntrl)! - fix(google): restore structured output parsing with includeRaw and reasoning blocks Ensure structured output parsers read `BaseMessage` text content when `includeRaw: true`, so responses that include reasoning/thought blocks plus JSON text continue to parse correctly. ## @langchain/google-gauth@2.1.30 ### Patch Changes - Updated dependencies \[[`dfec1b7`](dfec1b7)]: - @langchain/google-common@2.1.30 ## @langchain/google-vertexai@2.1.30 ### Patch Changes - Updated dependencies \[]: - @langchain/google-gauth@2.1.30 ## @langchain/google-vertexai-web@2.1.30 ### Patch Changes - Updated dependencies \[]: - @langchain/google-webauth@2.1.30 ## @langchain/google-webauth@2.1.30 ### Patch Changes - Updated dependencies \[[`dfec1b7`](dfec1b7)]: - @langchain/google-common@2.1.30 ## @langchain/google-genai@2.1.30 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
## Summary This PR stacks on [langchain-ai#10678](langchain-ai#10678) and consolidates the new chat model streaming protocol with the agent streaming work from [langchain-ai#10697](langchain-ai#10697). The first commit cherry-picks langchain-ai#10697 so the `ReactAgent` streaming changes can be developed and tested against the new chat model streaming primitives. The remaining commits align the stream event protocol, update the core stream aggregation behavior, refresh the Anthropic adapter, and add/adjust test coverage. ## What Changed ### Included From langchain-ai#10697 Cherry-picked the agent streaming work from langchain-ai#10697, including support for the new LangGraph streaming primitives in `ReactAgent`, native `toolCalls` and `middleware` stream projections, stream transformer typing, package exports, and related tests. This PR does not restate all of langchain-ai#10697 in detail; it carries that work here so the chat model stream protocol changes can be validated end-to-end with agent streaming. ### Chat Model Stream Protocol Consolidation - Standardized stream events on the `event` discriminator instead of `type`. - Renamed message finish response metadata from `responseMetadata` to `metadata`. - Simplified `content-block-delta` events so they carry incremental `content: ContentBlock` updates directly, instead of a separate delta union. - Widened stream usage inputs to allow partial usage snapshots from providers, while normalizing usage before exposing final `AIMessage` output. - Made `message-finish.reason` optional for providers that do not always emit a stop reason. ### Core Stream Behavior - Updated `ChatModelStream` and its typed substreams to consume the consolidated event shape. - Preserved append semantics for text, reasoning, and tool call chunk args. - Kept stable tool call `id` / `name` values when later chunks omit them. - Improved reasoning stream handling for reasoning/thinking blocks and finish boundaries. - Changed the usage substream to resolve to `undefined` when no usage was reported, instead of manufacturing an empty zero-token snapshot. ### Compatibility Bridge And Anthropic Adapter - Updated the legacy chunk-to-event bridge to emit the consolidated event format. - Updated Anthropic stream conversion to emit content block updates directly. - Preserved provider passthrough events for Anthropic-specific stream data. - Kept tool call finalization behavior, including JSON argument parsing and invalid tool call handling. ### Tests And Environment Coverage - Updated core stream protocol tests, stream assembly tests, and compatibility bridge tests. - Updated Anthropic stream event tests for the consolidated protocol. - Added CJS/export environment coverage needed for the new agent streaming exports. - Added a changeset covering the protocol consolidation. --------- Co-authored-by: Hunter Lovell <hunter@hntrl.io>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @langchain/perplexity@0.2.0 ### Minor Changes - [langchain-ai#10781](langchain-ai#10781) [`1f76917`](langchain-ai@1f76917) Thanks [@jliounis](https://github.com/jliounis)! - feat(perplexity): add Perplexity Search retriever (`PerplexitySearchRetriever`) and tool (`PerplexitySearchResults`) ## @langchain/core@1.1.43 ### Patch Changes - [langchain-ai#10814](langchain-ai#10814) [`dfec1b7`](langchain-ai@dfec1b7) Thanks [@hntrl](https://github.com/hntrl)! - fix(google): restore structured output parsing with includeRaw and reasoning blocks Ensure structured output parsers read `BaseMessage` text content when `includeRaw: true`, so responses that include reasoning/thought blocks plus JSON text continue to parse correctly. - [langchain-ai#10772](langchain-ai#10772) [`1ba7131`](langchain-ai@1ba7131) Thanks [@christian-bromann](https://github.com/christian-bromann)! - chore(core): new stream primitives ## @langchain/google-common@2.1.30 ### Patch Changes - [langchain-ai#10814](langchain-ai#10814) [`dfec1b7`](langchain-ai@dfec1b7) Thanks [@hntrl](https://github.com/hntrl)! - fix(google): restore structured output parsing with includeRaw and reasoning blocks Ensure structured output parsers read `BaseMessage` text content when `includeRaw: true`, so responses that include reasoning/thought blocks plus JSON text continue to parse correctly. ## @langchain/google-gauth@2.1.30 ### Patch Changes - Updated dependencies \[[`dfec1b7`](langchain-ai@dfec1b7)]: - @langchain/google-common@2.1.30 ## @langchain/google-vertexai@2.1.30 ### Patch Changes - Updated dependencies \[]: - @langchain/google-gauth@2.1.30 ## @langchain/google-vertexai-web@2.1.30 ### Patch Changes - Updated dependencies \[]: - @langchain/google-webauth@2.1.30 ## @langchain/google-webauth@2.1.30 ### Patch Changes - Updated dependencies \[[`dfec1b7`](langchain-ai@dfec1b7)]: - @langchain/google-common@2.1.30 ## @langchain/google-genai@2.1.30 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR stacks on [langchain-ai#10678](langchain-ai#10678) and consolidates the new chat model streaming protocol with the agent streaming work from [langchain-ai#10697](langchain-ai#10697). The first commit cherry-picks langchain-ai#10697 so the `ReactAgent` streaming changes can be developed and tested against the new chat model streaming primitives. The remaining commits align the stream event protocol, update the core stream aggregation behavior, refresh the Anthropic adapter, and add/adjust test coverage. Cherry-picked the agent streaming work from langchain-ai#10697, including support for the new LangGraph streaming primitives in `ReactAgent`, native `toolCalls` and `middleware` stream projections, stream transformer typing, package exports, and related tests. This PR does not restate all of langchain-ai#10697 in detail; it carries that work here so the chat model stream protocol changes can be validated end-to-end with agent streaming. - Standardized stream events on the `event` discriminator instead of `type`. - Renamed message finish response metadata from `responseMetadata` to `metadata`. - Simplified `content-block-delta` events so they carry incremental `content: ContentBlock` updates directly, instead of a separate delta union. - Widened stream usage inputs to allow partial usage snapshots from providers, while normalizing usage before exposing final `AIMessage` output. - Made `message-finish.reason` optional for providers that do not always emit a stop reason. - Updated `ChatModelStream` and its typed substreams to consume the consolidated event shape. - Preserved append semantics for text, reasoning, and tool call chunk args. - Kept stable tool call `id` / `name` values when later chunks omit them. - Improved reasoning stream handling for reasoning/thinking blocks and finish boundaries. - Changed the usage substream to resolve to `undefined` when no usage was reported, instead of manufacturing an empty zero-token snapshot. - Updated the legacy chunk-to-event bridge to emit the consolidated event format. - Updated Anthropic stream conversion to emit content block updates directly. - Preserved provider passthrough events for Anthropic-specific stream data. - Kept tool call finalization behavior, including JSON argument parsing and invalid tool call handling. - Updated core stream protocol tests, stream assembly tests, and compatibility bridge tests. - Updated Anthropic stream event tests for the consolidated protocol. - Added CJS/export environment coverage needed for the new agent streaming exports. - Added a changeset covering the protocol consolidation. --------- Co-authored-by: Hunter Lovell <hunter@hntrl.io>
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @langchain/perplexity@0.2.0 ### Minor Changes - [langchain-ai#10781](langchain-ai#10781) [`1f76917`](langchain-ai@1f76917) Thanks [@jliounis](https://github.com/jliounis)! - feat(perplexity): add Perplexity Search retriever (`PerplexitySearchRetriever`) and tool (`PerplexitySearchResults`) ## @langchain/core@1.1.43 ### Patch Changes - [langchain-ai#10814](langchain-ai#10814) [`dfec1b7`](langchain-ai@dfec1b7) Thanks [@hntrl](https://github.com/hntrl)! - fix(google): restore structured output parsing with includeRaw and reasoning blocks Ensure structured output parsers read `BaseMessage` text content when `includeRaw: true`, so responses that include reasoning/thought blocks plus JSON text continue to parse correctly. - [langchain-ai#10772](langchain-ai#10772) [`1ba7131`](langchain-ai@1ba7131) Thanks [@christian-bromann](https://github.com/christian-bromann)! - chore(core): new stream primitives ## @langchain/google-common@2.1.30 ### Patch Changes - [langchain-ai#10814](langchain-ai#10814) [`dfec1b7`](langchain-ai@dfec1b7) Thanks [@hntrl](https://github.com/hntrl)! - fix(google): restore structured output parsing with includeRaw and reasoning blocks Ensure structured output parsers read `BaseMessage` text content when `includeRaw: true`, so responses that include reasoning/thought blocks plus JSON text continue to parse correctly. ## @langchain/google-gauth@2.1.30 ### Patch Changes - Updated dependencies \[[`dfec1b7`](langchain-ai@dfec1b7)]: - @langchain/google-common@2.1.30 ## @langchain/google-vertexai@2.1.30 ### Patch Changes - Updated dependencies \[]: - @langchain/google-gauth@2.1.30 ## @langchain/google-vertexai-web@2.1.30 ### Patch Changes - Updated dependencies \[]: - @langchain/google-webauth@2.1.30 ## @langchain/google-webauth@2.1.30 ### Patch Changes - Updated dependencies \[[`dfec1b7`](langchain-ai@dfec1b7)]: - @langchain/google-common@2.1.30 ## @langchain/google-genai@2.1.30 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Summary
This PR stacks on #10678 and consolidates the new chat model streaming protocol with the agent streaming work from #10697.
The first commit cherry-picks #10697 so the
ReactAgentstreaming changes can be developed and tested against the new chat model streaming primitives. The remaining commits align the stream event protocol, update the core stream aggregation behavior, refresh the Anthropic adapter, and add/adjust test coverage.What Changed
Included From #10697
Cherry-picked the agent streaming work from #10697, including support for the new LangGraph streaming primitives in
ReactAgent, nativetoolCallsandmiddlewarestream projections, stream transformer typing, package exports, and related tests.This PR does not restate all of #10697 in detail; it carries that work here so the chat model stream protocol changes can be validated end-to-end with agent streaming.
Chat Model Stream Protocol Consolidation
eventdiscriminator instead oftype.responseMetadatatometadata.content-block-deltaevents so they carry incrementalcontent: ContentBlockupdates directly, instead of a separate delta union.AIMessageoutput.message-finish.reasonoptional for providers that do not always emit a stop reason.Core Stream Behavior
ChatModelStreamand its typed substreams to consume the consolidated event shape.id/namevalues when later chunks omit them.undefinedwhen no usage was reported, instead of manufacturing an empty zero-token snapshot.Compatibility Bridge And Anthropic Adapter
Tests And Environment Coverage