agents.planning.rewoo_tree_agentΒΆ

ReWOO Tree-based Planning Agent with Parallelizable Execution.

This agent implements the ReWOO (Reasoning without Observation) methodology with tree-based planning for parallelizable execution. It features:

  • Hierarchical tree planning with recursive decomposition

  • Parallelizable node execution with proper dependencies

  • Tool aliasing and forced tool choice

  • Structured output models with field validators

  • Plan-and-execute pattern with dynamic recompilation

  • LLM Compiler inspired parallelization

Reference: - ReWOO: https://langchain-ai.github.io/langgraph/tutorials/rewoo/rewoo/#solver - LLM Compiler: https://langchain-ai.github.io/langgraph/tutorials/llm-compiler/LLMCompiler/

ClassesΒΆ

PlanNode

A node in the planning tree representing a task.

PlanTree

A tree structure representing the complete execution plan.

ReWOOTreeAgent

ReWOO Tree-based Planning Agent with Parallelizable Execution.

ReWOOTreeAgentState

Enhanced state for ReWOO tree agent.

ReWOOTreeExecutorOutput

Structured output for the ReWOO tree executor.

ReWOOTreePlannerOutput

Structured output for the ReWOO tree planner.

TaskPriority

Priority levels for tasks.

TaskStatus

Status of tasks in the planning tree.

TaskType

Types of tasks in the planning tree.

ToolAlias

Tool alias configuration for forced tool choice.

Module ContentsΒΆ

class agents.planning.rewoo_tree_agent.PlanNode(/, **data)ΒΆ

Bases: pydantic.BaseModel

A node in the planning tree representing a task.

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)

add_child(child_id)ΒΆ

Add a child node.

Parameters:

child_id (str)

Return type:

None

add_dependency(dependency_id)ΒΆ

Add a dependency.

Parameters:

dependency_id (str)

Return type:

None

can_execute(completed_nodes)ΒΆ

Check if this node can be executed given completed nodes.

Parameters:

completed_nodes (set[str])

Return type:

bool

mark_completed(result=None)ΒΆ

Mark the task as completed.

Parameters:

result (Any)

Return type:

None

mark_failed(error)ΒΆ

Mark the task as failed.

Parameters:

error (str)

Return type:

None

mark_started()ΒΆ

Mark the task as started.

Return type:

None

validate_dependencies()ΒΆ

Validate dependency relationships.

Return type:

PlanNode

classmethod validate_id(v)ΒΆ

Validate node ID format.

Parameters:

v (str)

Return type:

str

model_configΒΆ

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

class agents.planning.rewoo_tree_agent.PlanTree(/, **data)ΒΆ

Bases: pydantic.BaseModel

A tree structure representing the complete execution plan.

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)

add_node(node)ΒΆ

Add a node to the tree.

Parameters:

node (PlanNode)

Return type:

None

get_completion_percentage()ΒΆ

Get the completion percentage of the plan.

Return type:

float

get_node(node_id)ΒΆ

Get a node by ID.

Parameters:

node_id (str)

Return type:

PlanNode | None

get_parallelizable_nodes()ΒΆ

Get nodes organized by parallelizable execution levels.

Return type:

list[list[PlanNode]]

get_ready_nodes()ΒΆ

Get nodes that are ready for execution.

Return type:

list[PlanNode]

has_failures()ΒΆ

Check if there are any failed nodes.

Return type:

bool

is_complete()ΒΆ

Check if the entire plan is complete.

Return type:

bool

mark_node_completed(node_id, result=None)ΒΆ

Mark a node as completed.

Parameters:
  • node_id (str)

  • result (Any)

Return type:

None

mark_node_failed(node_id, error)ΒΆ

Mark a node as failed.

Parameters:
Return type:

None

classmethod validate_id(v)ΒΆ

Validate plan tree ID format.

Parameters:

v (str)

Return type:

str

model_configΒΆ

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

class agents.planning.rewoo_tree_agent.ReWOOTreeAgent(**kwargs)ΒΆ

Bases: haive.agents.base.agent.Agent

ReWOO Tree-based Planning Agent with Parallelizable Execution.

This agent implements the ReWOO methodology with enhancements: - Hierarchical tree planning with recursive decomposition - Parallelizable execution with dependency management - Tool aliasing for forced tool choice - Structured output models with validation - LLM Compiler inspired optimizations

Initialize ReWOO Tree Agent.

add_tool_alias(alias, actual_tool, force_choice=True, **params)ΒΆ

Add a tool alias for forced tool choice.

Parameters:
  • alias (str)

  • actual_tool (str)

  • force_choice (bool)

Return type:

None

build_graph()ΒΆ

Build the execution graph for ReWOO tree agent.

Return type:

haive.core.graph.state_graph.base_graph2.BaseGraph

class agents.planning.rewoo_tree_agent.ReWOOTreeAgentState(/, **data)ΒΆ

Bases: haive.core.schema.prebuilt.messages_state.MessagesState

Enhanced state for ReWOO tree agent.

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.planning.rewoo_tree_agent.ReWOOTreeExecutorOutput(/, **data)ΒΆ

Bases: pydantic.BaseModel

Structured output for the ReWOO tree executor.

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.planning.rewoo_tree_agent.ReWOOTreePlannerOutput(/, **data)ΒΆ

Bases: pydantic.BaseModel

Structured output for the ReWOO tree planner.

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)

validate_consistency()ΒΆ

Validate consistency between plan components.

Return type:

ReWOOTreePlannerOutput

classmethod validate_plan_id(v)ΒΆ

Validate plan ID format.

Parameters:

v (str)

Return type:

str

model_configΒΆ

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

class agents.planning.rewoo_tree_agent.TaskPriorityΒΆ

Bases: str, enum.Enum

Priority levels for tasks.

Initialize self. See help(type(self)) for accurate signature.

class agents.planning.rewoo_tree_agent.TaskStatusΒΆ

Bases: str, enum.Enum

Status of tasks in the planning tree.

Initialize self. See help(type(self)) for accurate signature.

class agents.planning.rewoo_tree_agent.TaskTypeΒΆ

Bases: str, enum.Enum

Types of tasks in the planning tree.

Initialize self. See help(type(self)) for accurate signature.

class agents.planning.rewoo_tree_agent.ToolAlias(/, **data)ΒΆ

Bases: pydantic.BaseModel

Tool alias configuration for forced tool choice.

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)

classmethod validate_alias(v)ΒΆ

Validate alias format.

Parameters:

v (str)

Return type:

str

model_configΒΆ

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