agents.reasoning_and_critique.tot.models

Tree of Thoughts (ToT) models and data structures.

This module defines the core data models for the Tree of Thoughts reasoning algorithm, including candidate solutions and structured output models.

Classes

Candidate

A candidate solution in the Tree of Thoughts algorithm.

CandidateEvaluation

Structured output model for evaluating a candidate solution.

CandidateGeneration

Structured output model for generating multiple candidate solutions.

Equation

An equation in reverse-polish notation that combines numbers to reach a target value.

EquationGeneration

Specialized candidate generation for equation problems.

Score

A score with feedback.

ScoredCandidate

A candidate solution with its evaluation score.

Functions

update_candidates([existing, updates])

Update candidate list, handling special cases like clearing.

Module Contents

class agents.reasoning_and_critique.tot.models.Candidate(/, **data)

Bases: pydantic.BaseModel, Generic[T]

A candidate solution in the Tree of Thoughts algorithm.

This represents an unscored candidate solution generated by the LLM.

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)

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.reasoning_and_critique.tot.models.CandidateEvaluation(/, **data)

Bases: pydantic.BaseModel

Structured output model for evaluating a candidate solution.

This model is used when the evaluator LLM produces structured output.

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)

to_score()

Convert to a Score object.

Return type:

Score

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.reasoning_and_critique.tot.models.CandidateGeneration(/, **data)

Bases: pydantic.BaseModel, Generic[T]

Structured output model for generating multiple candidate solutions.

This model is used when the generator LLM produces structured output.

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)

to_candidates()

Convert candidate contents to Candidate objects.

Return type:

list[Candidate[T]]

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.reasoning_and_critique.tot.models.Equation(/, **data)

Bases: pydantic.BaseModel

An equation in reverse-polish notation that combines numbers to reach a target value.

This is one possible implementation of a solution type for mathematical problems.

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)

compute()

Compute the result of the equation.

Return type:

float

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.reasoning_and_critique.tot.models.EquationGeneration(/, **data)

Bases: pydantic.BaseModel

Specialized candidate generation for equation problems.

This is a structured output model for equation-specific generation.

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)

to_candidates()

Convert equations to Candidate objects.

Return type:

list[Candidate[Equation]]

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.reasoning_and_critique.tot.models.Score(/, **data)

Bases: pydantic.BaseModel

A score with feedback.

This represents the evaluation of a candidate solution.

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)

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class agents.reasoning_and_critique.tot.models.ScoredCandidate(/, **data)

Bases: pydantic.BaseModel, Generic[T]

A candidate solution with its evaluation score.

This combines a candidate solution with its score and feedback.

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)

property content: T

Get the content of the candidate.

Return type:

T

property feedback: str | None

Get the feedback if any.

Return type:

str | None

property metadata: dict[str, Any]

Get the metadata of the candidate.

Return type:

dict[str, Any]

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

property value: float

Get the numerical score value.

Return type:

float

agents.reasoning_and_critique.tot.models.update_candidates(existing=None, updates=None)

Update candidate list, handling special cases like clearing.

Parameters:
  • existing (list[Any] | None) – Current list of candidates

  • updates (list[Any] | str | None) – New candidates to add, or “clear” to empty the list

Returns:

Updated list of candidates

Return type:

list[Any]