ThinkNode

ThinkNode(content: str, parent: ForwardRef('ThinkNode') | None = None)

A node in a tree structure representing a step in the reasoning process.

This class implements a tree node that stores content (text describing a reasoning step), maintains parent-child relationships, tracks node statistics, and provides utilities for traversing/visualizing the reasoning path.

Parameters:
NameDescription
contentThe text content/description for this reasoning step.

Type: str
parentThe parent node in the tree, if any.

Type: ForwardRef('ThinkNode') | None

Default: None

Static Methods

from_dict

from_dict(data: dict, parent: ForwardRef('ThinkNode') | None = None) -> autogen.ThinkNode

Create ThinkNode from dictionary representation.

Parameters:
NameDescription
dataDictionary containing node data

Type: dict
parentParent node to attach to

Type: ForwardRef('ThinkNode') | None

Default: None
Returns:
TypeDescription
autogen.ThinkNodeThinkNode: Reconstructed node with all children

Instance Attributes

trajectory


Get a formatted string representation of the path from root to this node.

Returns: str: A formatted string showing the question and each step in the reasoning process

Instance Methods

backpropagate

backpropagate(self, reward: float) -> None

Update the score of this node and its parents using moving average.

Parameters:
NameDescription
rewardThe reward to backpropagate up the tree.

Type: float

to_dict

to_dict(self) -> dict

Convert ThinkNode to dictionary representation.

Returns: Dict: Dictionary containing all node attributes and recursive children

Returns:
TypeDescription
dictDict: Dictionary containing all node attributes and recursive children