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/svelteUseDeepAgentStream
Interface●Since v0.1

UseDeepAgentStream

Copy
interface UseDeepAgentStream

Bases

UseAgentStream<StateType, ToolCall, Bag>

Properties

Inherited fromUseAgentStream

Properties

PassistantId: string
—

The ID of the assistant to use.

Pbranch: string
—

The current branch of the thread.

Pclient: Client
—

LangGraph SDK client used to send requests and receive responses.

View source on GitHub
P
error
: unknown
—

Last seen error from the stream, if any.

Pexperimental_branchTree: Sequence<StateType>
—

Tree of all branches for the thread.

PgetMessagesMetadata: (message: Message<ToolCall>, index?: number)
—

Get the metadata for a message, such as first thread state the message

PgetToolCalls: (message: AIMessage<ToolCall>)
—

Get tool calls for a specific AI message.

Phistory: ThreadState<StateType>[]
—

Flattened history of thread states of a thread.

Pinterrupt: Interrupt<GetInterruptType<Bag>> | undefined
—

Current interrupt, if the stream is interrupted.

Pinterrupts: Interrupt<GetInterruptType<Bag>>[]
—

All current interrupts from the stream.

PisLoading: boolean
—

Whether the stream is currently running.

PisThreadLoading: boolean
—

Whether the thread is currently being loaded.

PjoinStream: (runId: string, lastEventId?: string, options?: __type)
—

Join an active stream that's already running.

Pmessages: Message<ToolCall>[]
—

Messages accumulated during the stream.

Pqueue: QueueInterface<StateRecord<StateType>, SubmitOptions<StateRecord<StateType>, GetConfigurableType<Bag>>>
—

Server-side submission queue. Pending runs created via

PsetBranch: (branch: string)
—

Set the branch of the thread.

Pstop: ()
—

Stops the currently running stream.

Psubmit: (values: GetUpdateType<Bag, StateRecord<StateType>> | null | undefined, options?: SubmitOptions<StateRecord<StateType>, GetConfigurableType<Bag>>)
—

Create and stream a run to the thread.

PswitchThread: (newThreadId: string | null)
—

Switch to a different thread, clearing the current stream state.

PtoolCalls: ToolCallWithResult<ToolCall>[]
—

Tool calls paired with their results.

PtoolProgress: ToolProgress[]
—

Progress of tool executions during streaming. Populated when stream mode includes "tools"

Pvalues: StateType
—

The current state values of the stream.

Example

property
activeSubagents: SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string>[]
property
assistantId: string
property
branch: string
property
client: Client
property
error: unknown
property
experimental_branchTree: Sequence<StateType>
property
getMessagesMetadata: (message: Message<ToolCall>, index?: number) => MessageMetadata<StateRecord<StateType>> | undefined
property
getSubagent: (toolCallId: string) => SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string> | undefined
property
getSubagentsByMessage: (messageId: string) => SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string>[]
property
getSubagentsByType: (type: TName) => SubagentStreamInterface<SubagentStates[TName], ToolCall, TName>[]
property
getToolCalls: (message: AIMessage<ToolCall>) => ToolCallWithResult<ToolCall>[]
property
history: ThreadState<StateType>[]
property
interrupt: Interrupt<GetInterruptType<Bag>> | undefined
property
interrupts: Interrupt<GetInterruptType<Bag>>[]
property
isLoading: boolean
property
isThreadLoading: boolean
property
joinStream: (runId: string, lastEventId?: string, options?: __type) => Promise<void>
property
messages: Message<ToolCall>[]
property
queue: QueueInterface<StateRecord<StateType>, SubmitOptions<StateRecord<StateType>, GetConfigurableType<Bag>>>
property
setBranch: (branch: string) => void
property
stop: () => Promise<void>
property
subagents: Map<string, SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string>>
property
submit: (values: GetUpdateType<Bag, StateRecord<StateType>> | null | undefined, options?: SubmitOptions<StateRecord<StateType>, GetConfigurableType<Bag>>) => Promise<void>
property
switchThread: (newThreadId: string | null) => void
property
toolCalls: ToolCallWithResult<ToolCall>[]
property
toolProgress: ToolProgress[]
property
values: StateType

Stream interface for DeepAgent instances created with createDeepAgent.

Extends UseAgentStream with subagent streaming capabilities. Subagent streams are automatically typed based on the agent's subagent configuration, enabling type-safe access to subagent state and messages.

Use this interface when streaming from an agent created with createDeepAgent that orchestrates multiple specialized subagents.

This interface is subject to change.

This interface adds subagent streaming on top of UseAgentStream:

  • subagents - Map of all subagent streams by tool call ID
  • activeSubagents - Array of currently running subagents
  • getSubagent(id) - Get a specific subagent by tool call ID
  • getSubagentsByType(type) - Get all subagents of a specific type with typed state
  • getSubagentsByMessage(messageId) - Get all subagents triggered by a specific AI message

It also enables the filterSubagentMessages option to exclude subagent messages from the main messages array.

Currently active subagents (where status === "running").

Use this to track and display subagents that are actively executing. Completed or errored subagents are not included.

The ID of the assistant to use.

The current branch of the thread. Used for navigating between different conversation branches.

LangGraph SDK client used to send requests and receive responses.

Last seen error from the stream, if any. Reset to undefined when a new stream starts.

Tree of all branches for the thread. This API is experimental and subject to change.

Get the metadata for a message, such as first thread state the message was seen in and branch information.

Get subagent stream by tool call ID.

Use this when you have a specific tool call ID and need to access its corresponding subagent stream.

Get all subagents triggered by a specific AI message.

Useful for rendering subagent activities grouped by conversation turn. Each AI message that contains subagent tool calls will have its triggered subagents returned by this method.

Get all subagents of a specific type.

Returns streams with properly inferred state types based on subagent name. When called with a literal string that matches a subagent name, TypeScript will infer the correct state type for that subagent.

Get tool calls for a specific AI message.

Use this to find which tool calls were initiated by a particular assistant message, useful for rendering tool calls inline with messages.

Flattened history of thread states of a thread. Contains all states in the current branch's history.

Current interrupt, if the stream is interrupted. Convenience alias for interrupts[0]. For workflows with multiple concurrent interrupts, use interrupts instead.

All current interrupts from the stream. When using Send() fan-out with per-task interrupt() calls, multiple interrupts may be pending simultaneously.

Whether the stream is currently running. true while streaming, false when idle or completed.

Whether the thread is currently being loaded. true during initial thread data fetch.

Join an active stream that's already running.

Messages accumulated during the stream. Includes both human and AI messages. AI messages include typed tool calls based on the agent's tools.

Server-side submission queue. Pending runs created via multitaskStrategy: "enqueue" when submitting while the agent is busy.

Set the branch of the thread.

Stops the currently running stream.

All currently active and completed subagent streams.

Keyed by tool call ID for easy lookup. Includes subagents in all states: pending, running, complete, and error.

Create and stream a run to the thread.

Switch to a different thread, clearing the current stream state. Pass null to reset to no thread (a new thread will be created on next submit).

Tool calls paired with their results.

Each entry contains the tool call request and its corresponding result. Useful for rendering tool invocations and their outputs together.

Progress of tool executions during streaming. Populated when stream mode includes "tools" and tools yield or report progress.

The current state values of the stream. Updated as streaming events are received.

Copy
import { createDeepAgent } from "deepagents";
import { useStream } from "@langchain/langgraph-sdk/react";

// Define subagents with typed middleware
const agent = createDeepAgent({
  subagents: [
    {
      name: "researcher",
      description: "Research specialist",
      middleware: [ResearchMiddleware],
    },
    {
      name: "writer",
      description: "Content writer",
      middleware: [WriterMiddleware],
    },
  ] as const, // Important: use 'as const' for type inference
});

// In React component:
function Chat() {
  const stream = useStream<typeof agent>({
    assistantId: "deep-agent",
    apiUrl: "http://localhost:2024",
    filterSubagentMessages: true, // Only show main agent messages
  });

  // Subagent streams are typed!
  const researchers = stream.getSubagentsByType("researcher");
  researchers.forEach(subagent => {
    // subagent.values.messages is typed as Message<ToolCall>[]
    // subagent.status is "pending" | "running" | "complete" | "error"
    console.log("Researcher status:", subagent.status);
  });

  // Track all active subagents
  stream.activeSubagents.forEach(subagent => {
    console.log(`${subagent.toolCall.args.subagent_type} is running...`);
  });
}
Copy
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
  <SubagentCard
    key={subagent.id}
    type={subagent.toolCall.args.subagent_type}
    isLoading={true}
  />
));
Copy
// In a tool call component
const subagent = stream.getSubagent(toolCall.id);
if (subagent) {
  return <SubagentProgress subagent={subagent} />;
}
Copy
// Get all researcher subagents with typed state
const researchers = stream.getSubagentsByType("researcher");

researchers.forEach(researcher => {
  // researcher.values is typed based on ResearchMiddleware
  console.log("Research messages:", researcher.values.messages.length);
  console.log("Status:", researcher.status);
});

// Get all writer subagents
const writers = stream.getSubagentsByType("writer");
// writers have different state type based on WriterMiddleware
Copy
messages.map(message => {
  if (message.type === "ai") {
    const calls = stream.getToolCalls(message);
    return (
      <>
        <MessageBubble message={message} />
        {calls.map(tc => <ToolCallCard key={tc.call.id} {...tc} />)}
      </>
    );
  }
  return <MessageBubble message={message} />;
});
Copy
// Iterate over all subagents
stream.subagents.forEach((subagent, toolCallId) => {
  console.log(`Subagent ${toolCallId}: ${subagent.status}`);
});

// Get a specific subagent
const specific = stream.subagents.get("call_abc123");
Copy
stream.toolCalls.map(({ call, result }) => (
  <ToolCallCard
    name={call.name}
    args={call.args}
    result={result}
  />
));
Copy
// Render subagents inline after the AI message that triggered them
{stream.messages.map((msg) => (
  <div key={msg.id}>
    <MessageBubble message={msg} />
    {msg.type === "ai" && "tool_calls" in msg && (
      <SubagentPipeline
        subagents={stream.getSubagentsByMessage(msg.id)}
      />
    )}
  </div>
))}