Skip to content

feat(core): new event streaming#10772

Merged
Christian Bromann (christian-bromann) merged 39 commits into
mainfrom
cb/new-chat-model-streaming
May 1, 2026
Merged

feat(core): new event streaming#10772
Christian Bromann (christian-bromann) merged 39 commits into
mainfrom
cb/new-chat-model-streaming

Conversation

@christian-bromann

@christian-bromann Christian Bromann (christian-bromann) commented Apr 24, 2026

Copy link
Copy Markdown
Member

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 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 #10697

Cherry-picked the agent streaming work from #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 #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.

@changeset-bot

changeset-bot Bot commented Apr 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a4840ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@langchain/core Patch
@langchain/classic Patch
langchain Patch
@langchain/anthropic Patch
@langchain/cohere Patch
@langchain/deepseek Patch
@langchain/fireworks Patch
@langchain/google-cloud-sql-pg Patch
@langchain/google-common Patch
@langchain/google-genai Patch
@langchain/google-webauth Patch
@langchain/ibm Patch
@langchain/neo4j Patch
@langchain/openai Patch
@langchain/openrouter Patch
@langchain/together-ai Patch
@langchain/xai Patch
@langchain/model-profiles Patch
@langchain/standard-tests Patch
@langchain/google-gauth Patch
@langchain/google-vertexai-web Patch
@langchain/google-vertexai Patch

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

@hntrl Hunter Lovell (hntrl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 delta semantics. 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 + reasoning fields (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
    • Hopefully we can do away with tool_call_chunk and server_tool_call_chunk if 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?

Comment thread libs/langchain-core/src/language_models/event.ts Outdated
Comment thread libs/langchain-core/src/language_models/event.ts Outdated
Comment thread libs/langchain/src/agents/ReactAgent.ts Outdated
@christian-bromann

Copy link
Copy Markdown
Member Author

Middleware isn't a protocol event right, it's just a projection of node events that we get from inside of a graph?

Correct, both toolCall and middleware stream transformer are just in-process stream projections.

@christian-bromann

Copy link
Copy Markdown
Member Author
  • I think we need to keep the delta semantics.

Kept delta semantics, see langchain-ai/agent-protocol#78

@christian-bromann Christian Bromann (christian-bromann) changed the base branch from hunter/chat-model-stream to main May 1, 2026 06:02
Hunter Lovell (hntrl) and others added 9 commits April 30, 2026 23:02
…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
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

📦 Dev Release Published

A dev release has been published for this PR!

Package Version
@langchain/core 1.1.43-dev-1777615538778
@langchain/perplexity 0.2.0-dev-1777615538778
langchain 1.4.0-dev-1777615538778

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

View workflow run

@christian-bromann Christian Bromann (christian-bromann) changed the title fix: updates to chat model stream / consolidation feat(core): new event streaming May 1, 2026

@hntrl Hunter Lovell (hntrl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we split up the langchain-core/langchain changes so we don't have to rely on a dev release?

@github-actions github-actions Bot added the ready label May 1, 2026
@christian-bromann Christian Bromann (christian-bromann) merged commit 1ba7131 into main May 1, 2026
39 checks passed
@christian-bromann Christian Bromann (christian-bromann) deleted the cb/new-chat-model-streaming branch May 1, 2026 23:45
Christian Bromann (christian-bromann) pushed a commit that referenced this pull request May 1, 2026
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>
Filip Żmijewski (FilipZmijewski) pushed a commit to FilipZmijewski/langchainjs that referenced this pull request May 12, 2026
## 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>
Filip Żmijewski (FilipZmijewski) pushed a commit to FilipZmijewski/langchainjs that referenced this pull request May 12, 2026
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>
Filip Żmijewski (FilipZmijewski) pushed a commit to FilipZmijewski/langchainjs that referenced this pull request May 12, 2026
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>
Filip Żmijewski (FilipZmijewski) pushed a commit to FilipZmijewski/langchainjs that referenced this pull request May 12, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants