| 11 | |
| 12 | |
| 13 | class BaseNode(BaseModel): |
| 14 | |
| 15 | state: Dict[str, str] = {"text": "", "extra_info": ""} |
| 16 | additional_state_keys: List[str] = [] |
| 17 | parent: Optional[Any] = None |
| 18 | children: List[Any] = [] |
| 19 | depth: int = 0 |
| 20 | is_terminal: bool = False |
| 21 | reward: Optional[float] = None |
| 22 | value: Optional[float] = -100 |
| 23 | |
| 24 | tag: str = "0" |
| 25 | consecutive_errors: int = 0 |
| 26 | |
| 27 | def __init__(self, **kwargs) -> None: |
| 28 | super().__init__(**kwargs) |
| 29 | |
| 30 | for key in self.additional_state_keys: |
| 31 | self.state[key] = "" |
| 32 | |
| 33 | def has_children(self) -> bool: |
| 34 | return self.children != [] |
| 35 | |
| 36 | def is_root(self) -> bool: |
| 37 | return self.parent is None |