haive.core.common.structures.tree_leaf.base¶
Base tree node classes with advanced generic support.
Classes¶
Module Contents¶
- class haive.core.common.structures.tree_leaf.base.Leaf[source]¶
Bases:
TreeNode[haive.core.common.structures.tree_leaf.generics.ContentT,haive.core.common.structures.tree_leaf.generics.ResultT],Generic[haive.core.common.structures.tree_leaf.generics.ContentT,haive.core.common.structures.tree_leaf.generics.ResultT]Leaf node - has content but no children.
Examples
# With explicit types leaf: Leaf[TaskContent, TaskResult] = Leaf( content=TaskContent(name="Calculate", action="add", params={"a": 1, "b": 2}) ) # With default types simple_leaf = Leaf(content=DefaultContent(name="Task1"))
- class haive.core.common.structures.tree_leaf.base.Tree[source]¶
Bases:
TreeNode[haive.core.common.structures.tree_leaf.generics.ContentT,haive.core.common.structures.tree_leaf.generics.ResultT],Generic[haive.core.common.structures.tree_leaf.generics.ContentT,haive.core.common.structures.tree_leaf.generics.ChildT,haive.core.common.structures.tree_leaf.generics.ResultT]Tree node - has content and children.
The ChildT parameter allows for heterogeneous trees where children can be of different types (but all extending the bound).
Examples
# Homogeneous tree (all children same type) tree: Tree[PlanContent, PlanNode, PlanResult] = Tree( content=PlanContent(objective="Main Plan") ) # Heterogeneous tree (mixed children) mixed: Tree[DefaultContent, TreeNode, DefaultResult] = Tree( content=DefaultContent(name="Root") )
- add_child(child: haive.core.common.structures.tree_leaf.generics.ChildT) haive.core.common.structures.tree_leaf.generics.ChildT[source]¶
- add_child(*children: haive.core.common.structures.tree_leaf.generics.ChildT) list[haive.core.common.structures.tree_leaf.generics.ChildT]
Add one or more children with auto-indexing.
- class haive.core.common.structures.tree_leaf.base.TreeNode(/, **data)[source]¶
Bases:
pydantic.BaseModel,Generic[haive.core.common.structures.tree_leaf.generics.ContentT,haive.core.common.structures.tree_leaf.generics.ResultT],abc.ABCAbstract base class for all tree nodes.
Uses bounded TypeVars for better type safety and inference.
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)