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.
npm install @langchain/svelte @langchain/core
Peer dependencies: svelte ^5.0.0, @langchain/core ^1.0.1
<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
streamhandle. Destructuring (const { messages } = stream) freezes the values at that moment — usestream.messagesin templates instead.
reconnectOnMount / joinStream dance.values, messages, toolCalls, and interrupts are reactive at the root with zero extra subscription cost.threadId. Pass threadId: () => active to drive in-place thread swaps without remounting.useStream<typeof agent>() unwraps state, tool calls, and subagent state maps from an agent brand.In-depth guides live in docs/:
useStream — options, return shape, reactive threadIduseMessages, useToolCalls, useValues, …)respond(), stop(), hydrationPromiseprovideStream / getStream)AgentServerAdapter, HttpAgentServerAdapter)@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.
For full end-to-end examples, see the LangChain UI Playground.
MIT
Public v1 name for TransportAdapter plus optional high-level capabilities. Renamed to reflect that this interface now denotes the full agent-server protocol contract (not merely wire transport): any o
Typed error thrown through media.stream / rejected from
media.blob / media.objectURL when a handle fails before its
message completes. Carries the bytes accumulated up to the failure
point on `p
Strip headless-tool interrupts from a user-facing interrupt list.
Execute and resume all newly seen headless-tool interrupts from a values
payload. Callers own handledIds and should clear it when the thread changes.
Reads the shared stream handle exposed by the nearest ancestor provideStream call. Throws when no ancestor has provided one.
Parses a headless-tool interrupt value from the graph. Accepts both
toolCall (LangChain JS) and tool_call (Python / JSON snake_case).
Creates a shared useStream handle and publishes it via
Svelte's setContext. Descendant components read it via
getStream.
Must be called during component initialisation (the top level of a `
Subscribe to a scoped audio-media stream. Each handle is yielded
on its first matching content-block-start, exposes
.partialBytes for live access, settles .blob / .objectURL /
.transcript on
Progressive audio playback for AudioMedia handles with a
uniform surface across PCM (streamed) and container
(HTMLAudioElement) strategies.
The Svelte binding mirrors the React / Vue equivalents: r
Side-effect counterpart to useChannel. Instead of returning a
reactive buffer, it invokes onEvent once per event for as long as
the calling scope is alive — the idiomatic place for analytics,
loggin
Subscribe to a custom:<name> stream extension — the most-recent
payload emitted by the transformer, scoped to the target namespace.
Returns only the latest value and resumes across serial runs, so
Subscribe to a scoped file-media stream. Pair with useMediaURL
for an <a download href> target.
Subscribe to a scoped image-media stream. Pair with useMediaURL
for <img src>.
Resolve the lazy MediaBase.objectURL promise into a
reactive string suitable for <audio src>, <img src>,
<video src>, or <a download href>. Reads .current for the
latest URL, or undefined
Read metadata recorded for a specific message id — today exposes
parentCheckpointId, the checkpoint the message was first seen
on. Designed for fork / edit flows:
<script lang="ts">
con
Subscribe to a scoped messages stream.
Contract:
target, or a static target that resolves to
the root namespace) returns a handle whose .current delegates
to `stream.meSvelte binding over ChannelRegistry.acquire. Mirrors the
React and Vue useProjection primitives with an idiomatic Svelte
shape:
$effect run the composable acquires a ref-countedSvelte 5 binding for the v2-native stream runtime.
Returns a handle whose reactive fields are plain getters on a
stable object — templates can read stream.messages directly and
`$derived(stream.isL
Subscribe to a scoped tools (tool-call) stream. Same target and
lifecycle rules as useMessages; at the root this returns a
handle delegating to stream.toolCalls.
Subscribe to a scoped values stream — the most recent state
payload for a namespace. At the root returns a handle delegating
to stream.values.
Typing:
useValues(stream)): returns tSubscribe to a scoped video-media stream. Pair with useMediaURL
for <video src>.
Bind a VideoMedia handle to a caller-owned <video>
element.
Svelte idioms:
videoRef accepts a raw HTMLVideoElement, a $state binding,
or a getter. Use Svelte 5's bind:this to assign a