Docsโ€บAgentโ€บAPI Referenceโ€บFetchStreamTransport

FetchStreamTransport

FetchStreamTransport is the production transport for LangGraph Platform. It wraps the LangGraph SDK client, creates threads when needed, starts streaming runs, joins queued runs, cancels runs, loads history, and updates thread state for operations such as regenerate rollback.

When you interact with it directly

In most apps you never instantiate FetchStreamTransport directly. When no custom transport is configured, agent() creates one from the resolved apiUrl and onThreadId callback.

You reach for it explicitly when you want to share a transport instance, inspect behavior in tests, or implement a custom transport by matching the same AgentTransport interface.

import { agent, FetchStreamTransport } from '@ngaf/langgraph';
 
const transport = new FetchStreamTransport(
  'http://localhost:2024',
  (threadId) => localStorage.setItem('threadId', threadId),
);
 
const chat = agent({
  apiUrl: 'http://localhost:2024',
  assistantId: 'support-agent',
  transport,
});

How it works

FetchStreamTransport creates a LangGraph SDK Client for the configured API URL. On stream(), it creates a thread when threadId is missing, calls client.runs.stream(...), normalizes SDK events into StreamEvent objects, and yields them to the stream manager.

The transport handles:

  • Thread creation โ€” calls onThreadId when the SDK creates a new thread.
  • Streaming modes โ€” defaults to values, messages-tuple, updates, and custom.
  • Cancellation โ€” forwards AbortSignal to LangGraph run APIs.
  • Queued runs โ€” supports create, cancel, and join flows when the backend supports them.
  • History and state update โ€” loads checkpoint history and calls threads.updateState() for regenerate rollback.
  • Error propagation โ€” SDK and network errors surface through agent.error().
Transport interface

FetchStreamTransport implements AgentTransport. Custom transports must implement stream(assistantId, threadId, payload, signal, options?); optional methods such as joinStream, createQueuedRun, cancelRun, getHistory, and updateState enable advanced LangGraph features.

What's Next

FetchStreamTransportclass

Production transport that connects to a LangGraph Platform API via HTTP and SSE. Creates threads automatically if no threadId is provided, and streams events using the LangGraph SDK client.

Parameters

ParameterTypeDescription
apiUrlstringBase URL of the LangGraph Platform API
onThreadId?objectOptional callback invoked when a new thread is created

Methods

cancelRun(threadId: string, runId: string, signal: AbortSignal)

Cancel a server-side run.

ParameterTypeDescription
threadIdstring
runIdstring
signalAbortSignal
createQueuedRun(assistantId: string, threadId: string, payload: unknown, signal: AbortSignal, options: LangGraphSubmitOptions)

Create a pending server-side run using LangGraph's enqueue strategy.

ParameterTypeDescription
assistantIdstring
threadIdstring
payloadunknown
signalAbortSignal
options?LangGraphSubmitOptions
getHistory(threadId: string, signal: AbortSignal)

Load persisted checkpoint history for a thread.

ParameterTypeDescription
threadIdstring
signalAbortSignal
joinStream(threadId: string, runId: string, lastEventId: string | undefined, signal: AbortSignal)

Join an already-started run without creating a new thread.

ParameterTypeDescription
threadIdstring
runIdstring
lastEventIdstring | undefined
signalAbortSignal
stream(assistantId: string, threadId: string | null, payload: unknown, signal: AbortSignal, options: LangGraphSubmitOptions)

Open a streaming connection, creating a thread if needed.

ParameterTypeDescription
assistantIdstring
threadIdstring | null
payloadunknown
signalAbortSignal
options?LangGraphSubmitOptions
updateState(threadId: string, values: Record<string, unknown>, _signal: AbortSignal)

Update server-side thread state, e.g. to remove messages for regenerate rollback.

ParameterTypeDescription
threadIdstring
valuesRecord<string, unknown>
_signalAbortSignal

Examples

const transport = new FetchStreamTransport(
  'http://localhost:2024',
  (id) => console.log('New thread:', id),
);