LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
React SDK
Vue SDK
Svelte SDK
Angular SDK
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
WebChannelsPregelPrebuiltRemote
React SDK
Vue SDK
Svelte SDK
Angular SDK
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/langgraph-sdkreactSubagentStreamInterface
Interface●Since v1.6

SubagentStreamInterface

Base interface for a single subagent stream. Tracks the lifecycle of a subagent from invocation to completion.

Extends StreamBase to share common properties with UseStream, allowing subagents to be treated similarly to the main stream.

Prefer using SubagentStream which supports passing an agent type directly for automatic type inference.

Copy
interface SubagentStreamInterface

Bases

StreamBase<StateType, ToolCall>

Properties

property
activeSubagents: SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]

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

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

Copy
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
  <SubagentCard
    key={subagent.id}
    type={subagent.toolCall.args.subagent_type}
    isLoading={true}
  />
));
property
completedAt: Date | null

Wall-clock timestamp when the task tool terminated (null if running).

property
depth: number

Nesting depth from the root (root = 0).

property
error: unknown
property
getSubagent: (toolCallId: string) => SubagentStreamInterface<Record<string, unknown>, ToolCall, string> | undefined

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.

Copy
// In a tool call component
const subagent = stream.getSubagent(toolCall.id);
if (subagent) {
  return <SubagentProgress subagent={subagent} />;
}
property
getSubagentsByMessage: (messageId: string) => SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]

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.

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>
))}
property
getSubagentsByType: (type: TName) => SubagentStreamInterface<Record<string, unknown>, ToolCall, TName>[]

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.

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
property
getToolCalls: (message: AIMessage<ToolCall>) => ToolCallWithResult<ToolCall>[]

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.

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} />;
});
property
id: string
property
interrupt: Interrupt<unknown> | undefined

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

property
interrupts: Interrupt<unknown>[]

Interrupt payloads collected during the run, if any. Mirrors the in-process run.interrupts.

property
isLoading: boolean

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

property
messages: Message<ToolCall>[]
property
namespace: string[]
property
parentId: string | null

Parent subagent id, or null if spawned from the root.

property
result: string | null
property
startedAt: Date | null

Wall-clock timestamp when the task tool started.

property
status: SubagentStatus
property
subagents: Map<string, SubagentStreamInterface<Record<string, unknown>, ToolCall, string>>
property
switchThread: (newThreadId: string | null) => void

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).

property
toolCall: SubagentToolCall<SubagentName>
property
toolCalls: ToolCallWithResult<ToolCall>[]
property
values: StateType

Inherited fromStreamBase

Properties

PactiveSubagents: SubagentStreamInterface<SubagentStates[keyof SubagentStates], ToolCall, keyof SubagentStates & string>[]
—

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

Perror: __typePgetSubagent: (toolCallId: string)
—

Get subagent stream by tool call ID.

PgetSubagentsByMessage: (messageId: string)
—

Get all subagents triggered by a specific AI message.

PgetSubagentsByType: (type: TName)
—

Get all subagents of a specific type.

PgetToolCalls: (message: AIMessage<ToolCall>)
—

Get tool calls for a specific AI message.

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

Current interrupt, if the stream is interrupted.

Pinterrupts: InterruptPayload<unknown>[]
—

Interrupt payloads collected during the run, if any.

PisLoading: boolean
—

Whether the stream is currently running.

Pmessages: "messages"Psubagents: AsyncIterable<SubagentHandle>PswitchThread: (newThreadId: string | null)
—

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

PtoolCalls: AsyncIterable<ClientAssembledToolCall<string, unknown, unknown>>Pvalues: "values"
View source on GitHub