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
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Server
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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
ClientAuthReactLoggingReact UiServer
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
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/svelteType safety

Type safety

@langchain/svelte is designed around agent-brand inference: pass typeof agent to the hook and get typed state, tool calls, and (for DeepAgents) subagent state maps back. Plain state generics still work for graphs that aren't built with the agent helpers.

Agent-brand inference

Pass typeof agent to infer state, tool-call union, and (for DeepAgents) subagent state map:

import type { agent } from "./agent";
import { useStream } from "@langchain/svelte";

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

  // stream.values is inferred
  // stream.toolCalls is a discriminated union of your tools
  // stream.subagents carries per-subagent state types
}

The same inference works on getStream<typeof agent>() and on the companion selector hooks when you pass a scoped target:

const messages = useMessages(stream); // BaseMessage[]
const tools = useToolCalls<typeof agent>(stream);
const state = useValues<typeof agent>(stream);

Custom state types

For plain state shapes, pass the state directly. The second and third generic slots are InterruptType and ConfigurableType:

import { useStream } from "@langchain/svelte";
import type { BaseMessage } from "@langchain/core/messages";

interface MyState {
  messages: BaseMessage[];
  context?: string;
}

const stream = useStream<MyState, { question: string }>({
  assistantId: "my-graph",
  apiUrl: "http://localhost:2024",
});

Prop-drilling the stream

Two type aliases cover the two common prop shapes:

  • UseStreamReturn<T> — fully-resolved return type. Use for { stream: UseStreamReturn<typeof agent> } props when the child needs typed access to state / tool calls. (UseStreamResult<T> is an alias of the same type.)
  • AnyStream — type-erased handle (UseStreamReturn<any, any, any>). Use when the child only forwards stream into selector hooks and doesn't care about the underlying state shape.
import type { AnyStream, UseStreamReturn } from "@langchain/svelte";
import type { agent } from "./agent";

function ChatPanel({ stream }: { stream: UseStreamReturn<typeof agent> }) {
  // stream.values is typed here
}

function SubgraphCard({
  stream,
  subgraph,
}: {
  stream: AnyStream;
  subgraph: SubgraphDiscoverySnapshot;
}) {
  // stream is only used to feed selector hooks — no generic required
}

Type helpers

Helper Use
InferStateType<T> Unwraps a compiled graph / agent brand / agent tool array into its state shape.
InferToolCalls<T> Derives a discriminated union of tool-call shapes.
InferToolOutput<T> Derives a single tool's output type.
InferSubagentStates<T> { name: State, … } map derived from a DeepAgent brand.
WidenUpdateMessages<T> Widens messages so both wire-format and BaseMessage instances typecheck in submit().
StreamSubmitOptions<State, Configurable> Options shape accepted by submit().
AgentServerAdapter / HttpAgentServerAdapter Custom-transport interface + convenience class. See Transports.
SelectorTarget / SubagentDiscoverySnapshot / SubgraphDiscoverySnapshot For components that render scoped views. See Selectors / Subagents.
AssembledToolCall, ToolCallStatus For rendering tool-call UI.
MessageMetadata, UseSubmissionQueueReturn, SubmissionQueueEntry Companion-hook return shapes. See Selectors.

API reference

Interfaces

Interface

UseStreamReturn

Svelte binding return type for useStream. Reactive projections are exposed as getters on a stable object so templates can read stream.messages directly without a .value / .current hop and `$deri

Interface

StreamSubmitOptions

Interface

AssembledToolCall

Reactive tool handle for framework bindings (stream.toolCalls, useToolCalls, injectToolCalls).

status, error, and output are plain values that the assembler updates in place as tool events arri

Interface

MessageMetadata

Metadata tracked per message id. Surfaced to applications via useMessageMetadata(stream, messageId).

Types

Type

InferStateType

Unwrap the state shape from a compiled graph, a create-agent brand, or a plain type. Used by useStream<T>() to resolve T = typeof agent into the state the values/messages projections observe.

Type

InferToolCalls

Infer the discriminated union of AssembledToolCall handles from an agent brand, an array of LangChain tools, or fall back to the untyped default handle.

Pass typeof agent or typeof tools and narr

Type

InferToolOutput

Infer the successful return type of a LangChain tool.

Resolution order mirrors InferToolInput: func, then invoke, then _call, so inference survives cross-package boundaries where _call is `pr

Type

InferSubagentStates

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

Type

WidenUpdateMessages

Widen an update type so its messages field also accepts @langchain/core BaseMessage class instances (single or array). Framework bindings apply this to submit() so callers can write `stream.subm

Type

UseStreamResult

Convenience alias for the fully-resolved stream handle type.

Type

AnyStream

Erased handle useful as a parameter type for helpers and wrapper components that pass a stream through to selector composables without reading values directly. Mirrors the React AnyStream alias.

Type

ToolCallStatus

High-level outcome of a single tool call.

Type

ToolCallState

The lifecycle state of a tool call.

  • pending: Tool call received, awaiting result
  • completed: Tool execution finished successfully
  • error: Tool execution failed (result.status === "error")
Type

DefaultToolCall

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

Type

ToolCallsFromTools

Infer a union of tool call types from an array of tools. Works with tools created via tool() from @langchain/core/tools.

Type

MessageMetadataMap

Read-only map exposed via MessageMetadataTracker.store.