LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Overview
  • Getting started
  • useStream
  • Selectors
  • Interrupts & headless tools
  • Subagents & subgraphs
  • Fork & edit from a checkpoint
  • Submission queue
  • Multimodal media
  • Transports
  • provideStream & context
  • Type safety
  • Migrating to v1
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
OverviewGetting starteduseStreamSelectorsInterrupts & headless toolsSubagents & subgraphsFork & edit from a checkpointSubmission queueMultimodal mediaTransportsprovideStream & contextType safetyMigrating to v1
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/svelteGetting started

Getting started

@langchain/svelte ships a useStream hook together with a small family of companion selector hooks. The root hook gives you always-on access to thread state, messages, tool calls, and interrupts; the selector hooks open ref-counted subscriptions for the things that aren't needed on every view (per-subagent messages, media streams, submission queue, message metadata, raw channels).

Learn more: For end-to-end tutorials and UI patterns, see the LangChain frontend documentation.

Installation

npm install @langchain/svelte @langchain/core

Peer dependencies: svelte (^5) and @langchain/core.

Your first chat

Mount useStream once per thread. Point it at a running agent server and render messages:

<script lang="ts">
  import { useStream } from "@langchain/svelte";

  const stream = useStream({
    assistantId: "agent",
    apiUrl: "http://localhost:2024",
  });
</script>

{#each stream.messages as msg, i (msg.id ?? i)}
  <div>{msg.content}</div>
{/each}

<button disabled={stream.isLoading} onclick={() => stream.submit({ messages: [{ type: "human", content: "Hello!" }] })}>
  Send
</button>

Use the graph name from your langgraph.json as assistantId.

Mental model

@langchain/svelte splits the surface into two layers:

  1. Root composable (useStream). Owns the thread lifecycle, the transport, and a handful of always-on projections: values, messages, toolCalls, interrupts, error, isLoading, and the subagent / subgraph discovery maps. Mount it once per thread.
  2. Companion composables. Each opens a ref-counted subscription when the first component mounts it and releases it when the last consumer unmounts. Use them for anything scoped to a namespace, a subagent / subgraph, a specific message, an extension channel, or a media stream.
import { useStream, useMessages, useSubmissionQueue } from "@langchain/svelte";

function Chat() {
  const stream = useStream({ assistantId: "agent", apiUrl: "/api" });

  // Root: free read, no new subscription.
  const messages = useMessages(stream); // same as stream.messages

  // Scoped: opens a subscription on mount.
  const queue = useSubmissionQueue(stream);
}

The key idea: views that don't render a subagent's messages never pay for that subagent's wire traffic. Subscriptions follow the component tree.

Runnable examples

The streaming cookbook collects end-to-end, runnable apps built on these hooks. Clone it and run any example from the typescript/ workspace:

Example Shows
ui-svelte A chat app with browser reconnect / replay — refresh mid-stream and reattach.
multimodal Streaming text, images, audio, and video from scoped graph nodes.
a2ui Generative UI rendered from a custom:a2ui extension channel.
react-custom-transport Wiring useStream to your own backend transport.
streaming Terminal scripts for messages, subgraphs, subagents, HITL, and more.

Where to go next

useStream

Every option, callback, and return value on the root hook.

Selectors

Scoped state, submission queue, message metadata, and raw events.

Interrupts

Pause for human approval, edits, or headless tool resolution.

Fork & edit

Edit a turn or retry from an earlier checkpoint.

Subagents

Visualize subagents and nested subgraphs with lazy subscriptions.

Multimodal

Stream audio, images, video, and files from scoped graph nodes.

Transports

Connect to Agent Server (SSE/WebSocket) or your own backend adapter.

Type safety

Full type inference from typeof agent and shared stream types.

Functions

Function

useStream

Svelte 5 binding for the v2-native stream runtime.