Implementation:Iamhankai Forest of Thought ToT Task Run
| Knowledge Sources | |
|---|---|
| Domains | Search_Algorithms, Reasoning |
| Last Updated | 2026-02-14 03:00 GMT |
Overview
Concrete tool for executing Tree-of-Thought search over reasoning steps provided by the Forest-of-Thought repository.
Description
The ToT_Task class extends SearchTask to implement Tree-of-Thought reasoning. It manages tree construction via DFS or BFS, step generation via LLM prompting, value estimation via LLM scoring, and final answer extraction via summary generation. The class supports configurable branching factor, maximum depth, value threshold gating, and both greedy and sampling-based selection.
Usage
Instantiated by Monte_Carlo_Forest.tot_run() with problem data and configuration. The run() method executes the full search and returns a result dictionary with the solution and correctness information.
Code Reference
Source Location
- Repository: Forest-of-Thought
- File: methods/tot/task.py
- Lines: L11-263
Signature
class ToT_Task(SearchTask):
def __init__(
self, data, propose_method='glm', value_method='glm',
algorithm='dfs', branch=1, select_branch=1,
max_depth=1, end_gate=0.9, select_method='greedy',
temperature=0.7, max_tokens=2048, seed=170,
max_length=2048, truncation=True, do_sample=True,
max_new_tokens=256, use_case_prompt=False,
low=0, high=1, evaluate='', multiply_value=False,
lang='en', answer=None, verify_method='string'
):
"""
Args:
data: Input problem text.
algorithm (str): Search method, 'dfs' or 'bfs'.
branch (int): Branching factor per step.
select_branch (int): Branches to pursue after evaluation.
max_depth (int): Maximum tree depth.
end_gate (float): Value threshold for stopping.
lang (str): Language ('en' or 'zh').
answer: Ground truth for verification.
"""
def run(self) -> tuple:
"""
Execute ToT search.
Returns:
tuple: (
result_dict: Dict with 'content', 'solution', 'summary',
'accurate', 'real_answer', 'multiply_value',
root: Root Node of the search tree
)
"""
Import
from methods.tot.task import ToT_Task
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data | str | Yes | Problem text to solve |
| algorithm | str | No | Search algorithm: dfs or bfs (default: dfs) |
| branch | int | No | Branching factor per step (default: 1) |
| max_depth | int | No | Maximum search depth (default: 1) |
| end_gate | float | No | Value threshold for stopping (default: 0.9) |
| answer | str | No | Ground truth for verification |
Outputs
| Name | Type | Description |
|---|---|---|
| result_dict | dict | Keys: content, solution, summary, accurate, real_answer |
| root | Node | Root node of the constructed search tree |
Usage Examples
from methods.tot.task import ToT_Task
task = ToT_Task(
data="Solve: What is 15 * 23?",
algorithm='dfs',
branch=3,
max_depth=4,
end_gate=0.9,
lang='en',
answer="345"
)
result, root = task.run()
print(f"Solution: {result['summary']}")
print(f"Correct: {result['accurate']}")