Skip to content

Nodes

Node

Bases: ABC

Represents a node in the graph.

The generic types define the type of state and shared state that the node expects. Due to variance the node can also take any subtype of the state and shared state.

The node must implement the run method, which will be called when the node is executed.

Source code in src/edgygraph/nodes.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Node[T: State = State, S: Shared = Shared](ABC):
    """
    Represents a node in the graph.

    The generic types define the type of state and shared state that the node expects.
    Due to variance the node can also take any subtype of the state and shared state.

    The node must implement the `run` method, which will be called when the node is executed.
    """

    @abstractmethod
    async def run(self, state: T, shared: S) -> None:
        """
        Runs the node with the given state and shared state from the graph.

        Operations on the state are merged in the graphs state after the node has finished.
        Therefore, the state is not shared between nodes and operations are safe.

        Operations on the shared state are reflected in all parallel running nodes.
        Therefore, the shared state is shared between nodes and operations are not safe without using the Lock.
        The lock can be accessed via `shared.lock`.

        Args:
            state: The state of the graph.
            shared: The shared state of the graph.

        Returns:
            None. The instance references of the arguments are used in the graph to enable variance.
        """
        pass

run(state, shared) abstractmethod async

Runs the node with the given state and shared state from the graph.

Operations on the state are merged in the graphs state after the node has finished. Therefore, the state is not shared between nodes and operations are safe.

Operations on the shared state are reflected in all parallel running nodes. Therefore, the shared state is shared between nodes and operations are not safe without using the Lock. The lock can be accessed via shared.lock.

Parameters:

Name Type Description Default
state T

The state of the graph.

required
shared S

The shared state of the graph.

required

Returns:

Type Description
None

None. The instance references of the arguments are used in the graph to enable variance.

Source code in src/edgygraph/nodes.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
@abstractmethod
async def run(self, state: T, shared: S) -> None:
    """
    Runs the node with the given state and shared state from the graph.

    Operations on the state are merged in the graphs state after the node has finished.
    Therefore, the state is not shared between nodes and operations are safe.

    Operations on the shared state are reflected in all parallel running nodes.
    Therefore, the shared state is shared between nodes and operations are not safe without using the Lock.
    The lock can be accessed via `shared.lock`.

    Args:
        state: The state of the graph.
        shared: The shared state of the graph.

    Returns:
        None. The instance references of the arguments are used in the graph to enable variance.
    """
    pass

START

Represents a start node

Source code in src/edgygraph/nodes.py
38
39
40
41
42
class START:
    """
    Represents a start node
    """
    pass

END

Represents an end node

Source code in src/edgygraph/nodes.py
44
45
46
47
48
class END:
    """
    Represents an end node
    """
    pass