LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph React SDK
  • React Ui
  • Server
LangGraph Vue SDK
LangGraph Svelte SDK
LangGraph Angular SDK
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 React SDK
React UiServer
LangGraph Vue SDK
LangGraph Svelte SDK
LangGraph Angular SDK
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/reactindexSubagentManager
Class●Since v0.1

SubagentManager

Copy
class SubagentManager

Constructors

Methods

View source on GitHub
constructor
constructor
method
addMessageToSubagent
method
clear
method
complete
method
getActiveSubagents→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]
method
getSubagent→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string> | undefined
method
getSubagents→ Map<string, SubagentStreamInterface<Record<string, unknown>, ToolCall, string>>
method
getSubagentsByMessage→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]
method
getSubagentsByType→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]
method
getToolCallIdFromNamespace→ string
method
hasSubagents→ boolean
method
isSubagentToolCall→ boolean
method
markRunning
method
markRunningFromNamespace
method
matchSubgraphToSubagent→ string | undefined
method
processToolMessage
method
reconstructFromMessages
method
registerFromToolCalls
method
updateSubagentValues

Manages subagent execution state.

Tracks subagents from the moment they are invoked (AI message with tool calls) through streaming to completion (tool message result).

Add a serialized message to a subagent from stream events.

This method handles the raw serialized message data from SSE events. Uses MessageTupleManager for proper chunk concatenation, matching how the main stream handles messages.

Clear all subagent state.

Complete a subagent with a result.

Called when a tool message is received for the subagent.

Get all currently running subagents. Filters out incomplete/phantom subagents.

Get a specific subagent by tool call ID.

Get all subagents as a Map. Filters out incomplete/phantom subagents that lack subagent_type.

Get all subagents triggered by a specific AI message.

Get all subagents of a specific type.

Get the tool call ID for a given namespace ID. Returns the namespace ID itself if no mapping exists.

Check if any subagents are currently tracked.

Check if a tool call is a subagent invocation.

Mark a subagent as running and update its namespace.

Called when update events are received with a namespace indicating which subagent is streaming.

Mark a subagent as running using a namespace ID. Resolves the namespace ID to the actual tool call ID via the mapping.

Try to match a subgraph to a pending subagent by description. Creates a mapping from namespace ID to tool call ID if a match is found.

Uses a multi-pass matching strategy:

  1. Exact description match
  2. Description contains/partial match
  3. Any unmapped pending subagent (fallback)

Process a tool message to complete a subagent.

Reconstruct subagent state from historical messages.

This method parses an array of messages (typically from thread history) to identify subagent executions and their results. It's used to restore subagent state after:

  • Page refresh (when stream has already completed)
  • Loading thread history
  • Navigating between threads

The reconstruction process:

  1. Find AI messages with tool calls matching subagent tool names
  2. Find corresponding tool messages with results
  3. Create SubagentStream entries with "complete" status

Note: Internal subagent messages (their streaming conversation) are not reconstructed since they are not persisted in the main thread state.

Register new subagent(s) from AI message tool calls.

Called when an AI message is received with tool calls. Creates pending subagent entries for each subagent tool call.

Update subagent values from a values stream event.

Called when a values event is received from a subagent's namespace. This populates the subagent's state values, making them accessible via the values property.