LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphwebStreamTransformer
Interface●Since v0.3

StreamTransformer

Observes ProtocolEvents during a graph run and builds typed derived projections (secondary event logs, promises, etc.).

Data is surfaced to consumers through projections returned from init(). Projections are merged into GraphRunStream.extensions for in-process consumers. Use StreamChannel.local for local streaming values, StreamChannel.remote for values that should also be visible to remote clients, or Promise<T> for final values.

To make projection data available to remote clients (SDK consumers over WebSocket / SSE), create a named channel with StreamChannel.remote(name). The StreamMux detects named StreamChannel instances in the init() return and auto-forwards every push() as a ProtocolEvent on the channel's named method. Remote clients subscribe via session.subscribe("custom:<name>").

finalize and fail are optional. When a transformer uses StreamChannel, the mux auto-closes/fails the channels on run completion — no manual lifecycle management needed. Implement finalize/fail only for non-channel teardown (e.g. resolving a Promise).

Copy
interface StreamTransformer

Methods

method
fail

Mark the channel as failed after all buffered items are consumed.

method
finalize→ void | PromiseLike<void>

Called once when the underlying Pregel run completes without throwing. Optional — only needed for non-channel teardown (e.g. resolving promises).

May return a PromiseLike<void> to defer the main event log close until the async work (e.g. emitting terminal lifecycle events) has completed. The mux awaits all returned promises before closing its event log.

method
init→ TProjection

Called once before the run starts.

method
onRegister

Optional hook invoked by StreamMux.addTransformer immediately after the transformer is attached to the mux. Receives a limited handle that exposes only StreamEmitter.push — enough for the transformer to emit synthesized ProtocolEvents on any namespace it chooses (e.g. a deepagents SubagentTransformer fabricating lifecycle/messages/values events under a ["tools:<tool_call_id>"] namespace when a task tool starts).

Transformers that do not synthesize events can omit this hook.

The StreamEmitter handle is only safe to call from within StreamTransformer.process. Emitting from an unrelated async context (e.g. after process has returned, from a setTimeout, etc.) races with the mux's close/fail cycle and may land events in an already-closed log.

method
process→ boolean

Called for each ProtocolEvent before it is appended to the main log.

View source on GitHub