Skip to content

Graph

graphorchestrator.graph.graph

Graph

Represents a directed graph composed of nodes and edges.

Attributes:

Name Type Description
nodes Dict[str, Node]

A dictionary mapping node IDs to Node objects.

concrete_edges List[ConcreteEdge]

A list of concrete edges in the graph.

conditional_edges List[ConditionalEdge]

A list of conditional edges in the graph.

start_node Node

The starting node of the graph.

end_node Node

The ending node of the graph.

Source code in graphorchestrator\graph\graph.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class Graph:
    """
    Represents a directed graph composed of nodes and edges.

    Attributes:
        nodes (Dict[str, Node]): A dictionary mapping node IDs to Node objects.
        concrete_edges (List[ConcreteEdge]): A list of concrete edges in the graph.
        conditional_edges (List[ConditionalEdge]): A list of conditional edges in the graph.
        start_node (Node): The starting node of the graph.
        end_node (Node): The ending node of the graph.
    """

    def __init__(
        self, start_node: Node, end_node: Node, name: Optional[str] = "graph"
    ) -> None:
        """
        Initializes a Graph object.

        Args:
            start_node (Node): The starting node of the graph.
            end_node (Node): The ending node of the graph.
            name (Optional[str]): An optional name for the graph (default: "graph").

        Raises:
            TypeError: If start_node or end_node is not of type Node.

        Returns:
            None
        """
        self.nodes: Dict[str, Node] = {}
        if not isinstance(start_node, Node) or not isinstance(end_node, Node):
            raise TypeError("start_node and end_node must be of type Node")

        self.concrete_edges: List[ConcreteEdge] = []
        self.conditional_edges: List[ConditionalEdge] = []
        self.start_node = start_node
        self.end_node = end_node

        GraphLogger.get().info(
            **wrap_constants(
                message="Graph initialized",
                **{
                    LC.EVENT_TYPE: "graph",
                    LC.ACTION: "graph_initialized",
                    LC.CUSTOM: {
                        "start_node_id": start_node.node_id,
                        "end_node_id": end_node.node_id,
                    },
                }
            )
        )

__init__(start_node, end_node, name='graph')

Initializes a Graph object.

Parameters:

Name Type Description Default
start_node Node

The starting node of the graph.

required
end_node Node

The ending node of the graph.

required
name Optional[str]

An optional name for the graph (default: "graph").

'graph'

Raises:

Type Description
TypeError

If start_node or end_node is not of type Node.

Returns:

Type Description
None

None

Source code in graphorchestrator\graph\graph.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def __init__(
    self, start_node: Node, end_node: Node, name: Optional[str] = "graph"
) -> None:
    """
    Initializes a Graph object.

    Args:
        start_node (Node): The starting node of the graph.
        end_node (Node): The ending node of the graph.
        name (Optional[str]): An optional name for the graph (default: "graph").

    Raises:
        TypeError: If start_node or end_node is not of type Node.

    Returns:
        None
    """
    self.nodes: Dict[str, Node] = {}
    if not isinstance(start_node, Node) or not isinstance(end_node, Node):
        raise TypeError("start_node and end_node must be of type Node")

    self.concrete_edges: List[ConcreteEdge] = []
    self.conditional_edges: List[ConditionalEdge] = []
    self.start_node = start_node
    self.end_node = end_node

    GraphLogger.get().info(
        **wrap_constants(
            message="Graph initialized",
            **{
                LC.EVENT_TYPE: "graph",
                LC.ACTION: "graph_initialized",
                LC.CUSTOM: {
                    "start_node_id": start_node.node_id,
                    "end_node_id": end_node.node_id,
                },
            }
        )
    )