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
Strip headless-tool interrupts from a user-facing interrupt list.
Execute and resume all newly seen headless-tool interrupts from a values
Reads the shared stream handle exposed by the nearest ancestor
Parses a headless-tool interrupt value from the graph. Accepts both
Creates a shared useStream handle and publishes it via
Subscribe to a scoped audio-media stream. Each handle is yielded
Progressive audio playback for AudioMedia handles with a
Side-effect counterpart to useChannel. Instead of returning a
Subscribe to a custom:<name> stream extension — the most-recent
Subscribe to a scoped file-media stream. Pair with useMediaURL
Subscribe to a scoped image-media stream. Pair with useMediaURL
Resolve the lazy MediaBase.objectURL promise into a
Read metadata recorded for a specific message id — today exposes
Subscribe to a scoped messages stream.
Svelte binding over ChannelRegistry.acquire. Mirrors the
Svelte 5 binding for the v2-native stream runtime.
Subscribe to a scoped tools (tool-call) stream. Same target and
Subscribe to a scoped values stream — the most recent state
Subscribe to a scoped video-media stream. Pair with useMediaURL
Bind a VideoMedia handle to a caller-owned <video>
Public v1 name for TransportAdapter plus optional high-level
Reactive tool handle for framework bindings (stream.toolCalls,
Shared surface across every media handle returned by
Player controls + live state returned by useAudioPlayer.
Shared surface across every media handle returned by
Client-side implementation returned by headlessTool.implement(...).
Represents a headless tool interrupt payload emitted by LangChain's
Shared surface across every media handle returned by
Shared surface across every media handle returned by
Metadata tracked per message id. Surfaced to applications via
Options for StreamController.stop / framework stop().
Lightweight discovery record for a subagent running inside the thread.
Lightweight discovery record for a subgraph running inside the thread.
Queued submission entry mirrored from the server-side run queue.
High-level wrapper around a protocol connection to a specific thread.
Stream interface for ReactAgent instances created with createAgent.
Options for configuring an agent stream.
Options for useAudioPlayer.
Options for useChannelEffect. Extends the projection options
Stream interface for DeepAgent instances created with createDeepAgent.
Options for configuring a deep agent stream.
Svelte binding return type for useStream. Reactive
Reactive handle on the server-side submission queue.
Options for useVideoPlayer.
Shared surface across every media handle returned by
Controls + live state returned by useVideoPlayer. Mirrors
Widens an update type so that its messages field also accepts
Erased handle useful as a parameter type for helpers and wrapper
Default tool call type when no specific tool definitions are provided.
Extract the tool call type from a StateType's messages property.
Unwrap the state shape from a compiled graph, a create-agent brand,
Infer the subagent → state map from a DeepAgent brand. Non-brands
Infer the discriminated union of AssembledToolCall handles
Infer the successful return type of a LangChain tool.
Kinds of failure that can terminate a media handle prematurely.
Block types this assembler knows how to reassemble into media handles.
Read-only map exposed via MessageMetadataTracker.store.
Lifecycle state of an audio or video player returned by
Props for provideStream when wiring a custom
Props for provideStream when talking to the default
Resolves the appropriate stream interface based on the agent/graph type.
Resolves the appropriate options interface based on the agent/graph type.
What a selector composable targets. Callers can pass:
Read-only snapshot of the queue. The queue store hands this out
Infer the streaming AssembledToolCall handle for a single
Infer a union of tool call types from an array of tools.
The lifecycle state of a tool call.
High-level outcome of a single tool call.
Convenience alias for the fully-resolved stream handle type.
Widen an update type so its messages field also accepts