ThoughtNode<T>

Helpers & Utilities · AiDotNet.Reasoning.Models

Represents a node in a tree of thoughts, used for exploring multiple reasoning paths.

For Beginners

Imagine you’re solving a complex problem and at each step, you could go in several different directions. A ThoughtNode represents one possible “thought” or direction you might explore.

Think of it like a choose-your-own-adventure book:

  • Each page (node) presents a situation (the thought)
  • Each page might have several choices that lead to different pages (children)
  • You can trace back through your choices (parent links)
  • Some paths lead to good endings (high scores), others to bad ones (low scores)

Tree-of-Thoughts reasoning builds a tree of these nodes, exploring different paths and choosing the best ones. It’s more sophisticated than just following one path (Chain-of-Thought) because it can compare alternatives and backtrack if needed.

How It Works

Example Usage:

Constructors

Constructor Summary
ThoughtNode() Initializes a new instance of the ThoughtNode class.

Properties

Property Summary
Dictionary<string, object> Metadata { get; set; } Additional context or metadata specific to this thought.
List<ThoughtNode<T>> Children { get; set; } Child nodes representing alternative next steps from this thought.
T EvaluationScore { get; set; } Quality score evaluating how promising this thought is (typically 0.0 to 1.0).
ThoughtNode<T> Parent { get; set; } The parent node that led to this thought (null for root node).
Vector<T> PathScores { get; } The complete path from root to this node as a Vector of scores.
bool IsTerminal { get; set; } Whether this node represents a complete solution or terminal state.
bool IsVisited { get; set; } Whether this node has been visited during tree exploration.
int Depth { get; set; } Depth level of this node in the tree (root = 0).
int PathLength { get; } Gets the number of nodes in the complete path from root to this node.
string Thought { get; set; } The thought or reasoning content at this node.

Methods

Method Summary
List<string> GetPathFromRoot() Gets the complete path of thoughts from root to this node as strings.
bool CheckIsTerminalByHeuristic() Checks if this node appears to be terminal based on heuristics.
bool IsLeaf() Checks if this node is a leaf (has no children).
bool IsRoot() Checks if this node is the root (has no parent).
string ToString() Returns a string representation of this thought node.