Subagent API surface parameterised by the subagent interface type.
Framework adapters supply a class-message variant of
SubagentStreamInterface (where messages is BaseMessage[]
from @langchain/core) so that consumers always work with class
instances. The default parameter keeps the SDK's plain Message
interface for direct SDK usage.
Currently active subagents (where status === "running").
Use this to track and display subagents that are actively executing. Completed or errored subagents are not included.
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.
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.
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
<SubagentCard
key={subagent.id}
type={subagent.toolCall.args.subagent_type}
isLoading={true}
/>
));// In a tool call component
const subagent = stream.getSubagent(toolCall.id);
if (subagent) {
return <SubagentProgress subagent={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 WriterMiddleware// 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");// 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>
))}