LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
LangGraph SDK
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • 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
ClientAuthReactLoggingReact UiServer
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-sdkreactSubagentManager
Class●Since v1.6

SubagentManager

Manages subagent execution state.

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

Copy
class SubagentManager

Constructors

constructor
constructor

Methods

method
addMessageToSubagent

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.

method
clear

Clear all subagent state.

method
complete

Complete a subagent with a result.

Called when a tool message is received for the subagent.

method
getActiveSubagents→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]

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

method
getSubagent→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string> | undefined

Get a specific subagent by tool call ID.

method
getSubagents→ Map<string, SubagentStreamInterface<Record<string, unknown>, ToolCall, string>>

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

method
getSubagentsByMessage→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]

Get all subagents triggered by a specific AI message.

method
getSubagentsByType→ SubagentStreamInterface<Record<string, unknown>, ToolCall, string>[]

Get all subagents of a specific type.

method
getToolCallIdFromNamespace→ string

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

method
hasSubagents→ boolean

Check if any subagents are currently tracked.

method
isSubagentToolCall→ boolean

Check if a tool call is a subagent invocation.

method
markRunning

Mark a subagent as running and update its namespace.

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

method
markRunningFromNamespace

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

method
matchSubgraphToSubagent→ string | undefined

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)
method
processToolMessage

Process a tool message to complete a subagent.

method
reconstructFromMessages

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.

method
registerFromToolCalls

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.

method
updateSubagentValues

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.

View source on GitHub