LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
  • 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
WebChannelsPregelPrebuiltRemoteStream
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/svelte

@langchain/svelte

Description

@langchain/svelte

Svelte 5 SDK for Deep Agents, LangChain and LangGraph.

useStream binds a LangGraph agent into a Svelte 5 component. Reactive fields are exposed as getters on a stable handle (stream.messages, stream.isLoading, …) so templates and $derived expressions track updates automatically — no stores, no $ prefix, no destructuring.

Installation

npm install @langchain/svelte @langchain/core

Peer dependencies: svelte ^5.0.0, @langchain/core ^1.0.1

Quick start

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

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

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

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

Note: Access fields through the live stream handle. Destructuring (const { messages } = stream) freezes the values at that moment — use stream.messages in templates instead.

Highlights

  • v2-native streaming protocol. Session-based transport with automatic re-attach on remount; no more reconnectOnMount / joinStream dance.
  • Always-on root projections. values, messages, toolCalls, and interrupts are reactive at the root with zero extra subscription cost.
  • Selector composables for scoped data. Per-subagent / per-subgraph messages, tool calls, and media stream only when a component actually mounts the matching composable, and release on unmount.
  • Discriminated option bag. The hosted Agent Server path and the custom-adapter path are two arms of a single typed union — mixing them is a compile-time error.
  • Reactive threadId. Pass threadId: () => active to drive in-place thread swaps without remounting.
  • Agent-brand type inference. useStream<typeof agent>() unwraps state, tool calls, and subagent state maps from an agent brand.
  • Multimodal media streams. Built-in assembly for audio, images, video, and files — plus opinionated playback helpers.
  • Headless tools. Register local tool implementations that auto-resolve server-emitted tool-call interrupts without a round-trip through the UI.

Documentation

In-depth guides live in docs/:

  • useStream — options, return shape, reactive threadId
  • Selector composables (useMessages, useToolCalls, useValues, …)
  • Interrupts, respond(), stop(), hydrationPromise
  • Submission queue
  • Stream context (provideStream / getStream)
  • Headless tools
  • Custom transport (AgentServerAdapter, HttpAgentServerAdapter)
  • Media (images, audio, video, files) & playback helpers
  • Type safety

Migrating from v0

@langchain/svelte v1 targets the v2 streaming protocol. The useStream import stays the same, but the option bag, return shape, and how you subscribe to scoped data all change. Most chat apps migrate in well under an hour — the full guide with line-by-line diffs lives in docs/v1-migration.md.

Playground

For full end-to-end examples, see the LangChain UI Playground.

License

MIT

Classes

Class

HttpAgentServerAdapter

Public v1 name for TransportAdapter plus optional high-level

Class

MediaAssemblyError

Typed error thrown through media.stream / rejected from

Functions

Function

executeHeadlessTool

Function

filterOutHeadlessToolInterrupts

Strip headless-tool interrupts from a user-facing interrupt list.

Function

findHeadlessTool

Function

flushPendingHeadlessToolInterrupts

Execute and resume all newly seen headless-tool interrupts from a values

Function

getStream

Reads the shared stream handle exposed by the nearest ancestor

Function

handleHeadlessToolInterrupt

Function

headlessToolResumeCommand

Function

isHeadlessToolInterrupt

Function

parseHeadlessToolInterruptPayload

Parses a headless-tool interrupt value from the graph. Accepts both

Function

provideStream

Creates a shared useStream handle and publishes it via

Function

useAudio

Subscribe to a scoped audio-media stream. Each handle is yielded

Function

useAudioPlayer

Progressive audio playback for AudioMedia handles with a

Function

useChannel

Function

useChannelEffect

Side-effect counterpart to useChannel. Instead of returning a

Function

useExtension

Subscribe to a custom:<name> stream extension — the most-recent

Function

useFiles

Subscribe to a scoped file-media stream. Pair with useMediaURL

Function

useImages

Subscribe to a scoped image-media stream. Pair with useMediaURL

Function

useMediaURL

Resolve the lazy MediaBase.objectURL promise into a

Function

useMessageMetadata

Read metadata recorded for a specific message id — today exposes

Function

useMessages

Subscribe to a scoped messages stream.

Function

useProjection

Svelte binding over ChannelRegistry.acquire. Mirrors the

Function

useStream

Svelte 5 binding for the v2-native stream runtime.

Function

useSubmissionQueue

Function

useToolCalls

Subscribe to a scoped tools (tool-call) stream. Same target and

Function

useValues

Subscribe to a scoped values stream — the most recent state

Function

useVideo

Subscribe to a scoped video-media stream. Pair with useMediaURL

Function

useVideoPlayer

Bind a VideoMedia handle to a caller-owned <video>

Interfaces

Types

Interface

AgentServerAdapter

Public v1 name for TransportAdapter plus optional high-level

Interface

AssembledToolCall

Reactive tool handle for framework bindings (stream.toolCalls,

Interface

AudioMedia

Shared surface across every media handle returned by

Interface

AudioPlayerHandle

Player controls + live state returned by useAudioPlayer.

Interface

FileMedia

Shared surface across every media handle returned by

Interface

FlushPendingHeadlessToolInterruptsOptions

Interface

HeadlessToolImplementation

Client-side implementation returned by headlessTool.implement(...).

Interface

HeadlessToolInterrupt

Represents a headless tool interrupt payload emitted by LangChain's

Interface

HttpAgentServerAdapterOptions

Interface

ImageMedia

Shared surface across every media handle returned by

Interface

MediaBase

Shared surface across every media handle returned by

Interface

MessageMetadata

Metadata tracked per message id. Surfaced to applications via

Interface

StreamStopOptions

Options for StreamController.stop / framework stop().

Interface

StreamSubmitOptions

Interface

SubagentDiscoverySnapshot

Lightweight discovery record for a subagent running inside the thread.

Interface

SubgraphDiscoverySnapshot

Lightweight discovery record for a subgraph running inside the thread.

Interface

SubmissionQueueEntry

Queued submission entry mirrored from the server-side run queue.

Interface

ThreadStream

High-level wrapper around a protocol connection to a specific thread.

Interface

ToolEvent

Interface

UseAgentStream

Stream interface for ReactAgent instances created with createAgent.

Interface

UseAgentStreamOptions

Options for configuring an agent stream.

Interface

UseAudioPlayerOptions

Options for useAudioPlayer.

Interface

UseChannelEffectOptions

Options for useChannelEffect. Extends the projection options

Interface

UseDeepAgentStream

Stream interface for DeepAgent instances created with createDeepAgent.

Interface

UseDeepAgentStreamOptions

Options for configuring a deep agent stream.

Interface

UseStreamReturn

Svelte binding return type for useStream. Reactive

Interface

UseSubmissionQueueReturn

Reactive handle on the server-side submission queue.

Interface

UseVideoPlayerOptions

Options for useVideoPlayer.

Interface

VideoMedia

Shared surface across every media handle returned by

Interface

VideoPlayerHandle

Controls + live state returned by useVideoPlayer. Mirrors

Type

AcceptBaseMessages

Widens an update type so that its messages field also accepts

Type

AgentServerOptions

Type

AnyHeadlessToolImplementation

Type

AnyMediaHandle

Type

AnyStream

Erased handle useful as a parameter type for helpers and wrapper

Type

CustomAdapterOptions

Type

DefaultToolCall

Default tool call type when no specific tool definitions are provided.

Type

GetToolCallsType

Extract the tool call type from a StateType's messages property.

Type

InferStateType

Unwrap the state shape from a compiled graph, a create-agent brand,

Type

InferSubagentStates

Infer the subagent → state map from a DeepAgent brand. Non-brands

Type

InferToolCalls

Infer the discriminated union of AssembledToolCall handles

Type

InferToolOutput

Infer the successful return type of a LangChain tool.

Type

MediaAssemblyErrorKind

Kinds of failure that can terminate a media handle prematurely.

Type

MediaBlockType

Block types this assembler knows how to reassemble into media handles.

Type

MessageMetadataMap

Read-only map exposed via MessageMetadataTracker.store.

Type

OnToolCallback

Type

PlayerStatus

Lifecycle state of an audio or video player returned by

Type

ProvideStreamCustomProps

Props for provideStream when wiring a custom

Type

ProvideStreamProps

Props for provideStream when talking to the default

Type

ResolveStreamInterface

Resolves the appropriate stream interface based on the agent/graph type.

Type

ResolveStreamOptions

Resolves the appropriate options interface based on the agent/graph type.

Type

SelectorTarget

What a selector composable targets. Callers can pass:

Type

SubmissionQueueSnapshot

Read-only snapshot of the queue. The queue store hands this out

Type

ToolCallFromTool

Infer the streaming AssembledToolCall handle for a single

Type

ToolCallsFromTools

Infer a union of tool call types from an array of tools.

Type

ToolCallState

The lifecycle state of a tool call.

Type

ToolCallStatus

High-level outcome of a single tool call.

Type

UseStreamOptions

Type

UseStreamResult

Convenience alias for the fully-resolved stream handle type.

Type

WidenUpdateMessages

Widen an update type so its messages field also accepts