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 SubagentStreamInterfaceCurrently active subagents (where status === "running").
Use this to track and display subagents that are actively executing. Completed or errored subagents are not included.
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
<SubagentCard
key={subagent.id}
type={subagent.toolCall.args.subagent_type}
isLoading={true}
/>
));When the subagent completed
Nesting depth (0 = called by main agent, 1 = called by subagent, etc.)
Last seen error from the stream, if any.
Reset to undefined when a new stream starts.
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.
// In a tool call component
const subagent = stream.getSubagent(toolCall.id);
if (subagent) {
return <SubagentProgress subagent={subagent} />;
}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.
// 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>
))}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 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 WriterMiddlewareGet 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.
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} />;
});The ID of the interrupt.
Whether the stream is currently running.
true while streaming, false when idle or completed.
Tool call ID of parent subagent (for nested subagents)
When the subagent started
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.
// 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");The tool call that invoked this subagent
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.
stream.toolCalls.map(({ call, result }) => (
<ToolCallCard
name={call.name}
args={call.args}
result={result}
/>
));The current state values of the stream. Updated as streaming events are received.