ThinkNode - AG2

ThinkNode

autogen.agents.experimental.ThinkNode

ThinkNode(content, parent=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.

PARAMETER DESCRIPTION
content The text content/description for this reasoning step.
TYPE:str
parent The parent node in the tree, if any.
TYPE:Optional[ThinkNode]DEFAULT:None
ATTRIBUTE DESCRIPTION
content The text content/description for this reasoning step.
TYPE:str
value A numeric score/value assigned to this node.
TYPE:float
parent Reference to the parent node.
TYPE:Optional[ThinkNode]
reflection A string containing reflections on the reasoning process.
TYPE:str
rating_details A string providing details about the rating of this node.
TYPE:str
output The output generated at this node through the execute_node method.
TYPE:Optional[str]
depth The depth of this node in the tree (root = 0).
TYPE:int
children list of child nodes.
TYPE:list[ThinkNode]
visits Number of times this node has been visited during search.
TYPE:int

The node automatically maintains the tree structure by:

content`instance-attribute

content = content

value`instance-attribute

value = 0.0

parent`instance-attribute

parent = parent

reflection`instance-attribute

reflection = ''

rating_details`instance-attribute

rating_details = ''

output`instance-attribute

output = None

depth`instance-attribute

depth = depth + 1 if parent is not None else 0

children`instance-attribute

children = []

visits`instance-attribute

visits = 0

trajectory`property

trajectory

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

RETURNS DESCRIPTION
str A formatted string showing the question and each step in the reasoning process
TYPE:str

backpropagate

backpropagate(reward)

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

PARAMETER DESCRIPTION
reward The reward to backpropagate up the tree.
TYPE:float

to_dict

to_dict()

Convert ThinkNode to dictionary representation.

RETURNS DESCRIPTION
dict[str, Any] dict[str, Any]: dictionary containing all node attributes and recursive children

from_dict classmethod

from_dict(data, parent=None)

Create ThinkNode from dictionary representation.

PARAMETER DESCRIPTION
data dictionary containing node data
TYPE:dict[str, Any]
parent Parent node to attach to
TYPE:Optional[ThinkNode]DEFAULT:None
RETURNS DESCRIPTION
ThinkNode Reconstructed node with all children
TYPE:ThinkNode

visualize_tree

visualize_tree()

Visualize the tree of thoughts using graphviz.