Manages subagent execution state.
Tracks subagents from the moment they are invoked (AI message with tool calls) through streaming to completion (tool message result).
class SubagentManagerAdd 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:
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:
The reconstruction process:
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.