LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
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
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServer
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-sdkuiSubagentApi
Interface●Since v1.7

SubagentApi

Copy
interface SubagentApi

Properties

View source on GitHub
property
activeSubagents: Iface[]
property
getSubagent: (toolCallId: string) => Iface | undefined
property
getSubagentsByMessage: (messageId: string) => Iface[]
property
getSubagentsByType: (type: string) => Iface[]
property
subagents: Map<string, Iface>

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.

Copy
// Show loading indicators for active subagents
stream.activeSubagents.map(subagent => (
  <SubagentCard
    key={subagent.id}
    type={subagent.toolCall.args.subagent_type}
    isLoading={true}
  />
));
Copy
// In a tool call component
const subagent = stream.getSubagent(toolCall.id);
if (subagent) {
  return <SubagentProgress subagent={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
Copy
// 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");
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>
))}