@@ -11,29 +11,29 @@ class BaseGraph:
1111 BaseGraph manages the execution flow of a graph composed of interconnected nodes.
1212
1313 Attributes:
14- nodes (dict ): A dictionary mapping each node's name to its corresponding node instance.
15- edges (dict ): A dictionary representing the directed edges of the graph where each
14+ nodes (list ): A dictionary mapping each node's name to its corresponding node instance.
15+ edges (list ): A dictionary representing the directed edges of the graph where each
1616 key-value pair corresponds to the from-node and to-node relationship.
1717 entry_point (str): The name of the entry point node from which the graph execution begins.
1818
1919 Methods:
20- execute(initial_state): Executes the graph's nodes starting from the entry point and
20+ execute(initial_state): Executes the graph's nodes starting from the entry point and
2121 traverses the graph based on the provided initial state.
2222
2323 Args:
2424 nodes (iterable): An iterable of node instances that will be part of the graph.
25- edges (iterable): An iterable of tuples where each tuple represents a directed edge
25+ edges (iterable): An iterable of tuples where each tuple represents a directed edge
2626 in the graph, defined by a pair of nodes (from_node, to_node).
2727 entry_point (BaseNode): The node instance that represents the entry point of the graph.
2828 """
2929
30- def __init__ (self , nodes : list , edges : dict , entry_point : str ):
30+ def __init__ (self , nodes : list , edges : list , entry_point : str ):
3131 """
3232 Initializes the graph with nodes, edges, and the entry point.
3333 """
3434
35- self .nodes = { node . node_name : node for node in nodes }
36- self .edges = self ._create_edges (edges )
35+ self .nodes = nodes
36+ self .edges = self ._create_edges ({ e for e in edges } )
3737 self .entry_point = entry_point .node_name
3838
3939 if nodes [0 ].node_name != entry_point .node_name :
@@ -58,8 +58,8 @@ def _create_edges(self, edges: list) -> dict:
5858
5959 def execute (self , initial_state : dict ) -> dict :
6060 """
61- Executes the graph by traversing nodes starting from the entry point. The execution
62- follows the edges based on the result of each node's execution and continues until
61+ Executes the graph by traversing nodes starting from the entry point. The execution
62+ follows the edges based on the result of each node's execution and continues until
6363 it reaches a node with no outgoing edges.
6464
6565 Args:
@@ -68,6 +68,7 @@ def execute(self, initial_state: dict) -> dict:
6868 Returns:
6969 dict: The state after execution has completed, which may have been altered by the nodes.
7070 """
71+ print (self .nodes )
7172 current_node_name = self .nodes [0 ]
7273 state = initial_state
7374
0 commit comments