|
6 | 6 | class BaseNode(ABC): |
7 | 7 | """ |
8 | 8 | Abstract base class for all nodes in the exospherehost system. |
9 | | - |
10 | | - BaseNode provides the foundation for creating executable nodes that can be |
11 | | - connected to a Runtime for distributed processing. Each node must implement |
12 | | - the execute method and can optionally define Inputs and Outputs models. |
13 | | - |
| 9 | +
|
| 10 | + This class defines the interface and structure for executable nodes that can be |
| 11 | + managed by an Exosphere Runtime. Subclasses should define their own `Inputs` and |
| 12 | + `Outputs` models (as subclasses of pydantic.BaseModel) to specify the input and |
| 13 | + output schemas for the node, and must implement the `execute` method containing |
| 14 | + the node's main logic. |
| 15 | +
|
14 | 16 | Attributes: |
15 | | - unique_name (Optional[str]): A unique identifier for this node instance. |
16 | | - If None, the class name will be used as the unique name. |
17 | | - state (dict[str, Any]): A dictionary for storing node state between executions. |
| 17 | + inputs (Optional[BaseNode.Inputs]): The validated input data for the node execution. |
18 | 18 | """ |
19 | 19 |
|
20 | 20 | def __init__(self): |
21 | 21 | """ |
22 | 22 | Initialize a BaseNode instance. |
23 | | - |
24 | | - Args: |
25 | | - unique_name (Optional[str], optional): A unique identifier for this node. |
26 | | - If None, the class name will be used as the unique name. Defaults to None. |
| 23 | +
|
| 24 | + Sets the `inputs` attribute to None. The `inputs` attribute will be populated |
| 25 | + with validated input data before execution. |
27 | 26 | """ |
28 | 27 | self.inputs: Optional[BaseNode.Inputs] = None |
29 | 28 |
|
30 | 29 | class Inputs(BaseModel): |
31 | 30 | """ |
32 | | - Pydantic model for defining the input schema of a node. |
33 | | - |
34 | | - Subclasses should override this class to define the expected input structure. |
35 | | - This ensures type safety and validation of inputs before execution. |
| 31 | + Input schema for the node. |
| 32 | +
|
| 33 | + Subclasses should override this class to define the expected input fields. |
36 | 34 | """ |
37 | 35 | pass |
38 | 36 |
|
39 | 37 | class Outputs(BaseModel): |
40 | 38 | """ |
41 | | - Pydantic model for defining the output schema of a node. |
42 | | - |
43 | | - Subclasses should override this class to define the expected output structure. |
44 | | - This ensures type safety and validation of outputs after execution. |
| 39 | + Output schema for the node. |
| 40 | +
|
| 41 | + Subclasses should override this class to define the expected output fields. |
45 | 42 | """ |
46 | 43 | pass |
47 | 44 |
|
48 | 45 | async def _execute(self, inputs: Inputs) -> Outputs | List[Outputs]: |
49 | 46 | """ |
50 | | - Execute the node's main logic. |
| 47 | + Internal method to execute the node with validated inputs. |
| 48 | +
|
| 49 | + Args: |
| 50 | + inputs (Inputs): The validated input data for this execution. |
| 51 | +
|
| 52 | + Returns: |
| 53 | + Outputs | List[Outputs]: The output(s) produced by the node. |
51 | 54 | """ |
52 | 55 | self.inputs = inputs |
53 | 56 | return await self.execute() |
54 | 57 |
|
55 | 58 | @abstractmethod |
56 | 59 | async def execute(self) -> Outputs | List[Outputs]: |
57 | 60 | """ |
58 | | - Execute the node's main logic. |
59 | | - |
60 | | - This is the core method that must be implemented by all concrete node classes. |
61 | | - It receives inputs, processes them according to the node's logic, and returns |
62 | | - outputs. The method can return either a single Outputs instance or a list |
63 | | - of Outputs instances for batch processing. |
64 | | - |
65 | | - Args: |
66 | | - inputs (Inputs): The input data for this execution, validated against |
67 | | - the Inputs model defined by the node. |
68 | | - |
| 61 | + Main logic for the node. |
| 62 | +
|
| 63 | + This method must be implemented by all subclasses. It should use `self.inputs` |
| 64 | + (populated with validated input data) to perform the node's computation and |
| 65 | + return either a single Outputs instance or a list of Outputs instances. |
| 66 | +
|
69 | 67 | Returns: |
70 | | - Outputs | List[Outputs]: The output data from this execution. Can be |
71 | | - a single Outputs instance or a list of Outputs instances. |
72 | | - |
| 68 | + Outputs | List[Outputs]: The output(s) produced by the node. |
| 69 | +
|
73 | 70 | Raises: |
74 | | - Exception: Any exception that occurs during execution will be caught |
75 | | - by the Runtime and reported as an error state. |
| 71 | + Exception: Any exception raised here will be caught and reported as an error state by the Runtime. |
76 | 72 | """ |
77 | 73 | raise NotImplementedError("execute method must be implemented by all concrete node classes") |
0 commit comments