Skip to content

Class: ThreadNode

@providerprotocol/agents


@providerprotocol/agents / thread-tree / 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.

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

// Create a node manually (typically done via ThreadTree.branch())
const node = new ThreadNode(
generateUUID(),
parentNodeId,
currentAgentState,
'experiment-1'
);
// Access node properties
console.log(node.id); // UUIDv4 identifier
console.log(node.parentId); // Parent's ID or null for root
console.log(node.children); // Array of child node IDs

new ThreadNode(id, parentId, state, name?, children?): ThreadNode

Defined in: src/thread-tree/index.ts:74

Creates a new ThreadNode instance.

string

Unique identifier for this node (typically a UUIDv4)

ID of the parent node, or null for root nodes

string | null

AgentState

The agent state snapshot to store at this node

string

Optional human-readable name for the branch

string[] = []

Array of child node IDs (defaults to empty array)

ThreadNode

readonly children: 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().


readonly id: string

Defined in: src/thread-tree/index.ts:40

Unique identifier for this node (UUIDv4 format).


optional name: string

Defined in: src/thread-tree/index.ts:57

Optional human-readable name for this branch. Useful for identifying specific conversation paths.


readonly parentId: 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.

toJSON(): ThreadNodeJSON

Defined in: src/thread-tree/index.ts:99

Serializes this node to a JSON-compatible object.

ThreadNodeJSON

A plain object representation suitable for JSON.stringify()

const json = node.toJSON();
const serialized = JSON.stringify(json);

static fromJSON(json): ThreadNode

Defined in: src/thread-tree/index.ts:121

Deserializes a ThreadNode from a JSON object.

ThreadNodeJSON

The serialized node data

ThreadNode

A new ThreadNode instance with the restored data

const json = JSON.parse(savedData) as ThreadNodeJSON;
const node = ThreadNode.fromJSON(json);