LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
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
LangGraph SDK
ClientAuthReactLoggingReact UiServer
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/langgraph-sdkreactUseAgentStreamOptions
Interface●Since v1.6

UseAgentStreamOptions

Copy
interface UseAgentStreamOptions

Bases

UseStreamOptions<StateType, Bag>

Properties

Inherited fromUseStreamOptions

Properties

PapiKey: string | null
—

API key for authentication.

PapiUrl: stringPassistantId: string
—

The ID of the assistant to use.

View source on GitHub
P
callerOptions
: AsyncCallerParams
Pclient: Client
—

LangGraph SDK client used to send requests and receive responses.

PdefaultHeaders: Record<string, HeaderValue>
PfetchStateHistory: boolean | __type
—

Whether to fetch the history of the thread.

PinitialValues: StateType | null
—

Initial values to display immediately when loading a thread.

PmessagesKey: string
—

Specify the key within the state that contains messages.

PonCheckpointEvent: (data: __type, options: __type)
—

Callback that is called when a checkpoints event is received.

PonCreated: (run: RunCallbackMeta)
—

Callback that is called when a new stream is created.

PonCustomEvent: (data: GetCustomEventType<Bag>, options: __type)
—

Callback that is called when a custom event is received.

PonError: (error: unknown, run: RunCallbackMeta | undefined)
—

Callback that is called when an error occurs.

PonFinish: (state: ThreadState<StateType>, run: RunCallbackMeta | undefined)
—

Callback that is called when the stream is finished.

PonLangChainEvent: (data: __type)
—

Callback that is called when a LangChain event is received.

PonMetadataEvent: (data: __type)
—

Callback that is called when a metadata event is received.

PonStop: (options: __type)
—

Callback that is called when the stream is stopped by the user.

PonTaskEvent: (data: __type | __type | __type, options: __type)
—

Callback that is called when a tasks event is received.

PonThreadId: (threadId: string)
—

Callback that is called when the thread ID is updated (ie when a new thread is created).

PonUpdateEvent: (data: __type, options: __type)
—

Callback that is called when an update event is received.

PreconnectOnMount: boolean | ()
—

Will reconnect the stream on mount

Pthread: UseStreamThread<StateType>
—

Manage the thread state externally.

PthreadId: string | null
—

The ID of the thread to fetch history and current values from.

Pthrottle: number | boolean
—

Throttle the stream.

Example

property
apiKey: string | null
property
apiUrl: string
property
assistantId: string
property
callerOptions: AsyncCallerParams
property
client: Client<DefaultValues, DefaultValues, unknown>
property
defaultHeaders: Record<string, HeaderValue>
property
fetchStateHistory: boolean | __type
property
initialValues: StateType | null
property
messagesKey: string
property
onCheckpointEvent: (data: __type, options: __type) => void
property
onCreated: (run: RunCallbackMeta) => void
property
onCustomEvent: (data: GetCustomEventType<Bag>, options: __type) => void
property
onError: (error: unknown, run: RunCallbackMeta | undefined) => void
property
onFinish: (state: ThreadState<StateType>, run: RunCallbackMeta | undefined) => void
property
onLangChainEvent: (data: __type) => void
property
onMetadataEvent: (data: __type) => void
property
onStop: (options: __type) => void
property
onTaskEvent: (data: __type | __type | __type, options: __type) => void
property
onThreadId: (threadId: string) => void
property
onUpdateEvent: (data: __type, options: __type) => void
property
reconnectOnMount: boolean | () => RunMetadataStorage
property
thread: UseStreamThread<StateType>
property
threadId: string | null
property
throttle: number | boolean

Options for configuring an agent stream.

Use this options interface when calling useStream with a ReactAgent created via createAgent.

This interface is subject to change.

API key for authentication.

  • If a string is provided, that key will be used
  • If undefined (default), the key will be auto-loaded from environment variables (LANGGRAPH_API_KEY, LANGSMITH_API_KEY, or LANGCHAIN_API_KEY)
  • If null, no API key will be set (skips auto-loading)

The ID of the assistant to use.

LangGraph SDK client used to send requests and receive responses.

Whether to fetch the history of the thread. If true, the history will be fetched from the server. Defaults to 10 entries. If false, only the last state will be fetched from the server.

Initial values to display immediately when loading a thread. Useful for displaying cached thread data while official history loads. These values will be replaced when official thread data is fetched.

Note: UI components from initialValues will render immediately if they're predefined in LoadExternalComponent's components prop, providing instant cached UI display without server fetches.

Specify the key within the state that contains messages. Defaults to "messages".

Callback that is called when a checkpoints event is received.

Callback that is called when a new stream is created.

Callback that is called when a custom event is received.

Callback that is called when an error occurs.

Callback that is called when the stream is finished.

Callback that is called when a LangChain event is received.

Callback that is called when a metadata event is received.

Callback that is called when the stream is stopped by the user. Provides a mutate function to update the stream state immediately without requiring a server roundtrip.

Callback that is called when a tasks event is received.

Callback that is called when the thread ID is updated (ie when a new thread is created).

Callback that is called when an update event is received.

Will reconnect the stream on mount

Manage the thread state externally.

The ID of the thread to fetch history and current values from.

Throttle the stream. If a number is provided, the stream will be throttled to the given number of milliseconds. If true, updates are batched in a single macrotask. If false, updates are not throttled or batched.

Copy
const stream = useStream<typeof agent>({
  assistantId: "my-agent",
  apiUrl: "http://localhost:2024",
  onError: (error) => console.error(error),
});
Copy
onStop: ({ mutate }) => {
  mutate((prev) => ({
    ...prev,
    ui: prev.ui?.map(component =>
      component.props.isLoading
        ? { ...component, props: { ...component.props, stopped: true, isLoading: false }}
        : component
    )
  }));
}