LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph React SDK
  • React Ui
  • Server
LangGraph Vue SDK
LangGraph Svelte SDK
LangGraph Angular SDK
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • 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 React SDK
React UiServer
LangGraph Vue SDK
LangGraph Svelte SDK
LangGraph Angular SDK
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServer
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/svelteUseAgentStreamOptions
Interface●Since v0.1

UseAgentStreamOptions

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.

Copy
interface UseAgentStreamOptions

Bases

UseStreamOptions<StateType, Bag>

Properties

Inherited fromUseStreamOptions

Properties

PapiKey: string | null
—

The API key to use.

PapiUrl: string
—

The URL of the API to use.

PassistantId: string
—

The ID of the assistant to use.

View source on GitHub
P
callerOptions
: AsyncCallerParams
—

Custom call options, such as custom fetch implementation.

Pclient: Client<DefaultValues, DefaultValues, unknown>
—

Client used to send requests.

PdefaultHeaders: Record<string, HeaderValue>
—

Default headers to send with requests.

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).

PonToolEvent: (data: ToolStreamEventData, options: __type)
—

Callback that is called when a tool lifecycle event is received.

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
onToolEvent: (data: ToolStreamEventData, options: __type) => void
property
onUpdateEvent: (data: __type, options: __type) => void
property
reconnectOnMount: boolean | () => RunMetadataStorage
property
thread: UseStreamThread<StateType>
property
threadId: string | null
property
throttle: number | boolean

The API key to use.

The URL of the API to use.

The ID of the assistant to use.

Custom call options, such as custom fetch implementation.

Client used to send requests.

Default headers to send with requests.

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 a tool lifecycle event is received.

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
    )
  }));
}