agents.reasoning_and_critique.tot.tree_of_thoughts_agent

Tree of Thoughts Multi-Agent Implementation.

This implements the complete Tree of Thoughts algorithm using MultiAgent with proper LangGraph routing, conditional edges, and send-based branching.

Classes

TOTCommand

Commands for Tree of Thoughts routing.

TOTIteration

State for a single TOT iteration.

TreeOfThoughtsAgent

Tree of Thoughts agent using multi-agent coordination with conditional routing.

Functions

create_tree_of_thoughts_agent([beam_size, ...])

Create a Tree of Thoughts agent with default settings.

Module Contents

class agents.reasoning_and_critique.tot.tree_of_thoughts_agent.TOTCommand(/, **data)

Bases: pydantic.BaseModel

Commands for Tree of Thoughts routing.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class agents.reasoning_and_critique.tot.tree_of_thoughts_agent.TOTIteration(/, **data)

Bases: pydantic.BaseModel

State for a single TOT iteration.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

class agents.reasoning_and_critique.tot.tree_of_thoughts_agent.TreeOfThoughtsAgent(name='tree_of_thoughts', beam_size=3, max_iterations=3, generation_temperature=0.7, scoring_temperature=0.3, engine=None)

Tree of Thoughts agent using multi-agent coordination with conditional routing.

Initialize Tree of Thoughts agent.

Parameters:
  • name (str) – Agent name

  • beam_size (int) – Number of top solutions to keep in beam search

  • max_iterations (int) – Maximum TOT iterations

  • generation_temperature (float) – Temperature for candidate generation

  • scoring_temperature (float) – Temperature for solution scoring

  • engine (haive.core.engine.aug_llm.AugLLMConfig | None) – Optional engine configuration

build_graph_config()

Build the graph configuration with conditional edges and routing.

Return type:

dict[str, Any]

async expand_candidates_node(state)

Expand candidates from a seed solution.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

dict[str, Any]

async finalize_result_node(state)

Finalize the TOT result with the best solution.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

dict[str, Any]

async generate_candidates_node(state)

Generate initial candidate solutions.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

dict[str, Any]

route_tot_action(state)

Route TOT actions using Send for parallel processing.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

list[langgraph.constants.Send]

async score_solutions_node(state)

Score all candidate solutions.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

dict[str, Any]

should_continue(state)

Determine if TOT should continue or finish.

Returns:

“continue” to keep iterating, “finish” to end

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

str

async solve_problem(problem)

Solve a problem using Tree of Thoughts algorithm.

Parameters:

problem (str) – Problem statement to solve

Returns:

Dictionary with the best solution and metadata

Return type:

dict[str, Any]

async start_node(state)

Initialize TOT state.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

dict[str, Any]

async update_iteration_node(state)

Update iteration state and prepare for next iteration.

Parameters:

state (haive.core.schema.prebuilt.multi_agent_state.MultiAgentState)

Return type:

dict[str, Any]

agents.reasoning_and_critique.tot.tree_of_thoughts_agent.create_tree_of_thoughts_agent(beam_size=3, max_iterations=3, generation_temperature=0.7, scoring_temperature=0.3)

Create a Tree of Thoughts agent with default settings.

Parameters:
  • beam_size (int) – Number of top solutions to keep in beam search

  • max_iterations (int) – Maximum TOT iterations

  • generation_temperature (float) – Temperature for candidate generation

  • scoring_temperature (float) – Temperature for solution scoring

Returns:

Configured TreeOfThoughtsAgent

Return type:

TreeOfThoughtsAgent