langchain.js
    Preparing search index...

    Interface SubagentStreamInterface<StateType, ToolCall, SubagentName>

    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.

    interface SubagentStreamInterface<
        StateType = Record<string, unknown>,
        ToolCall = DefaultToolCall,
        SubagentName extends string = string,
    > {
        activeSubagents: SubagentStreamInterface<
            Record<string, unknown>,
            ToolCall,
            string,
        >[];
        completedAt: null | Date;
        depth: number;
        error: unknown;
        getSubagent: (
            toolCallId: string,
        ) =>
            | undefined
            | SubagentStreamInterface<Record<string, unknown>, ToolCall, string>;
        getSubagentsByMessage: (
            messageId: string,
        ) => SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[];
        getSubagentsByType: {
            <TName extends string>(
                type: TName,
            ): SubagentStreamInterface<Record<string, unknown>, ToolCall, TName>[];
            (
                type: string,
            ): SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[];
        };
        getToolCalls: (
            message: AIMessage<ToolCall>,
        ) => ToolCallWithResult<ToolCall>[];
        id: string;
        interrupt: undefined | Interrupt<unknown>;
        interrupts: Interrupt<unknown>[];
        isLoading: boolean;
        messages: Message<ToolCall>[];
        namespace: string[];
        parentId: null | string;
        result: null | string;
        startedAt: null | Date;
        status: SubagentStatus;
        subagents: Map<
            string,
            SubagentStreamInterface<Record<string, unknown>, ToolCall, string>,
        >;
        toolCall: SubagentToolCall<SubagentName>;
        toolCalls: ToolCallWithResult<ToolCall>[];
        values: StateType;
    }

    Type Parameters

    • StateType = Record<string, unknown>

      The state type of the subagent. Defaults to Record<string, unknown> since different subagents may have different state types. Can be narrowed using DeepAgent type helpers like InferSubagentByName when the specific subagent is known.

    • ToolCall = DefaultToolCall

      The type of tool calls in messages.

    • SubagentName extends string = string

      The subagent name union type. When inferred from a DeepAgent, enables typed toolCall.args.subagent_type.

    Hierarchy

    Index

    Properties

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

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

    completedAt: null | Date

    When the subagent completed

    depth: number

    Nesting depth (0 = called by main agent, 1 = called by subagent, etc.)

    error: unknown

    Last seen error from the stream.

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

    Get subagent stream by tool call ID.

    Type Declaration

      • (
            toolCallId: string,
        ):
            | undefined
            | SubagentStreamInterface<Record<string, unknown>, ToolCall, string>
      • Parameters

        • toolCallId: string

          The tool call ID that initiated the subagent.

        Returns undefined | SubagentStreamInterface<Record<string, unknown>, ToolCall, string>

        The subagent stream, or undefined if not found.

    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 the AI message (and therefore conversation turn) that spawned them.

    Type Declaration

    // Render subagents after each 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>
    ))}
    getSubagentsByType: {
        <TName extends string>(
            type: TName,
        ): SubagentStreamInterface<Record<string, unknown>, ToolCall, TName>[];
        (
            type: string,
        ): SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[];
    }

    Get all subagents of a specific type. When called with a literal type name that matches a key in SubagentStates, returns streams with properly inferred state types.

    The subagent_type to filter by.

    Array of matching subagent streams with inferred state types.

    // With DeepAgent type inference
    const stream = useStream<typeof agent>(...);
    const researchers = stream.getSubagentsByType("researcher");
    // researchers[0].values is typed with ResearcherMiddleware state
    getToolCalls: (message: AIMessage<ToolCall>) => ToolCallWithResult<ToolCall>[]

    Get tool calls for a specific AI message.

    Type Declaration

    id: string

    Unique identifier (the tool call ID)

    interrupt: undefined | Interrupt<unknown>

    Get the interrupt value for the stream if interrupted. Convenience alias for interrupts[0].

    interrupts: Interrupt<unknown>[]

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

    isLoading: boolean

    Whether the stream is currently running.

    messages: Message<ToolCall>[]

    Messages accumulated during the stream.

    namespace: string[]

    Namespace path for this subagent execution

    parentId: null | string

    Tool call ID of parent subagent (for nested subagents)

    result: null | string

    Final result content (when complete)

    startedAt: null | Date

    When the subagent started

    Current execution status

    subagents: Map<
        string,
        SubagentStreamInterface<Record<string, unknown>, ToolCall, string>,
    >

    All currently active and completed subagent streams. Keyed by tool call ID for easy lookup.

    The tool call that invoked this subagent

    Tool calls paired with their results. Useful for rendering tool invocations and their outputs together.

    values: StateType

    The current state values of the stream.