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.
interface UseDeepAgentStreamUseAgentStream<StateType, ToolCall, Bag>This interface adds subagent streaming on top of UseAgentStream:
subagents - Map of all subagent streams by tool call IDactiveSubagents - Array of currently running subagentsgetSubagent(id) - Get a specific subagent by tool call IDgetSubagentsByType(type) - Get all subagents of a specific type with typed stategetSubagentsByMessage(messageId) - Get all subagents triggered by a specific AI messageIt also enables the filterSubagentMessages option to exclude subagent
messages from the main messages array.
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...`);
});
}Currently active subagents (where status === "running").
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.
Get subagent stream by tool call ID.
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.
// 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>
))}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.
// With DeepAgent type inference
const stream = useStream<typeof agent>(...);
const researchers = stream.getSubagentsByType("researcher");
// researchers[0].values is typed with ResearcherMiddleware stateGet tool calls for a specific AI message.
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.
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.
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. 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.
The ID of the assistant to use.
The current branch of the thread.
LangGraph SDK client used to send requests and receive responses.
Last seen error from the stream, if any.
Tree of all branches for the thread.
Get the metadata for a message, such as first thread state the message
Get tool calls for a specific AI message.
Flattened history of thread states of a thread.
Current interrupt, if the stream is interrupted.
All current interrupts from the stream.
Whether the stream is currently running.
Whether the thread is currently being loaded.
Join an active stream that's already running.
Messages accumulated during the stream.
Server-side submission queue. Pending runs created via
Set the branch of the thread.
Stops the currently running stream.
Create and stream a run to the thread.
Switch to a different thread, clearing the current stream state.
Tool calls paired with their results.
Progress of tool executions during streaming. Populated when stream mode includes "tools"
The current state values of the stream.
The ID of the assistant to use.
The current branch of the thread.
LangGraph SDK client used to send requests and receive responses.
Last seen error from the stream, if any.
Tree of all branches for the thread.
Get the metadata for a message, such as first thread state the message
Flattened history of thread states of a thread.
Current interrupt, if the stream is interrupted.
All current interrupts from the stream.
Whether the stream is currently running.
Whether the thread is currently being loaded.
Join an active stream that's already running.
Messages accumulated during the stream.
Server-side submission queue. Pending runs created via
Set the branch of the thread.
Stops the currently running stream.
Create and stream a run to the thread.
Switch to a different thread, clearing the current stream state.
Progress of tool executions during streaming. Populated when stream mode includes "tools"
The current state values of the stream.