Class: ThreadNode
@providerprotocol/agents / thread-tree / ThreadNode
Class: ThreadNode
Section titled “Class: ThreadNode”Defined in: src/thread-tree/index.ts:36
A node in the thread tree representing a conversation state snapshot.
Each ThreadNode captures a complete snapshot of the agent state at a specific point in the conversation. Nodes form a tree structure where each node can have multiple children, enabling branching conversations and exploration of alternative dialogue paths.
Remarks
Section titled “Remarks”Nodes store full state copies rather than deltas, which simplifies branch switching at the cost of increased memory usage. This design choice makes checkout operations O(1) rather than requiring path reconstruction.
ThreadTree - The container class that manages collections of nodes
Example
Section titled “Example”// Create a node manually (typically done via ThreadTree.branch())const node = new ThreadNode( generateUUID(), parentNodeId, currentAgentState, 'experiment-1');
// Access node propertiesconsole.log(node.id); // UUIDv4 identifierconsole.log(node.parentId); // Parent's ID or null for rootconsole.log(node.children); // Array of child node IDsConstructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ThreadNode(
id,parentId,state,name?,children?):ThreadNode
Defined in: src/thread-tree/index.ts:74
Creates a new ThreadNode instance.
Parameters
Section titled “Parameters”string
Unique identifier for this node (typically a UUIDv4)
parentId
Section titled “parentId”ID of the parent node, or null for root nodes
string | null
The agent state snapshot to store at this node
string
Optional human-readable name for the branch
children?
Section titled “children?”string[] = []
Array of child node IDs (defaults to empty array)
Returns
Section titled “Returns”ThreadNode
Properties
Section titled “Properties”children
Section titled “children”
readonlychildren:string[]
Defined in: src/thread-tree/index.ts:63
IDs of all child nodes branching from this node. Modified when new branches are created via ThreadTree.branch().
readonlyid:string
Defined in: src/thread-tree/index.ts:40
Unique identifier for this node (UUIDv4 format).
optionalname:string
Defined in: src/thread-tree/index.ts:57
Optional human-readable name for this branch. Useful for identifying specific conversation paths.
parentId
Section titled “parentId”
readonlyparentId:string|null
Defined in: src/thread-tree/index.ts:45
ID of the parent node, or null if this is the root node.
state:
AgentState
Defined in: src/thread-tree/index.ts:51
Complete agent state snapshot at this point in the conversation. This is mutable to allow state updates on the current node.
Methods
Section titled “Methods”toJSON()
Section titled “toJSON()”toJSON():
ThreadNodeJSON
Defined in: src/thread-tree/index.ts:99
Serializes this node to a JSON-compatible object.
Returns
Section titled “Returns”A plain object representation suitable for JSON.stringify()
Example
Section titled “Example”const json = node.toJSON();const serialized = JSON.stringify(json);fromJSON()
Section titled “fromJSON()”
staticfromJSON(json):ThreadNode
Defined in: src/thread-tree/index.ts:121
Deserializes a ThreadNode from a JSON object.
Parameters
Section titled “Parameters”The serialized node data
Returns
Section titled “Returns”ThreadNode
A new ThreadNode instance with the restored data
Example
Section titled “Example”const json = JSON.parse(savedData) as ThreadNodeJSON;const node = ThreadNode.fromJSON(json);