BaseGraph manages the execution flow of a graph composed of interconnected nodes. Attributes: nodes (list): A dictionary mapping each node's name to its corresponding node instance. edges (list): A dictionary representing the directed edges of the graph where each
| 16 | CLICKABLE_URL = "\033]8;;https://scrapegraphai.com\033\\https://scrapegraphai.com\033]8;;\033\\" |
| 17 | |
| 18 | class BaseGraph: |
| 19 | """ |
| 20 | BaseGraph manages the execution flow of a graph composed of interconnected nodes. |
| 21 | |
| 22 | Attributes: |
| 23 | nodes (list): A dictionary mapping each node's name to its corresponding node instance. |
| 24 | edges (list): A dictionary representing the directed edges of the graph where each |
| 25 | key-value pair corresponds to the from-node and to-node relationship. |
| 26 | entry_point (str): The name of the entry point node from which the graph execution begins. |
| 27 | |
| 28 | Args: |
| 29 | nodes (iterable): An iterable of node instances that will be part of the graph. |
| 30 | edges (iterable): An iterable of tuples where each tuple represents a directed edge |
| 31 | in the graph, defined by a pair of nodes (from_node, to_node). |
| 32 | entry_point (BaseNode): The node instance that represents the entry point of the graph. |
| 33 | |
| 34 | Raises: |
| 35 | Warning: If the entry point node is not the first node in the list. |
| 36 | |
| 37 | Example: |
| 38 | >>> BaseGraph( |
| 39 | ... nodes=[ |
| 40 | ... fetch_node, |
| 41 | ... parse_node, |
| 42 | ... rag_node, |
| 43 | ... generate_answer_node, |
| 44 | ... ], |
| 45 | ... edges=[ |
| 46 | ... (fetch_node, parse_node), |
| 47 | ... (parse_node, rag_node), |
| 48 | ... (rag_node, generate_answer_node) |
| 49 | ... ], |
| 50 | ... entry_point=fetch_node, |
| 51 | ... use_burr=True, |
| 52 | ... burr_config={"app_instance_id": "example-instance"} |
| 53 | ... ) |
| 54 | """ |
| 55 | |
| 56 | def __init__( |
| 57 | self, |
| 58 | nodes: list, |
| 59 | edges: list, |
| 60 | entry_point: str, |
| 61 | use_burr: bool = False, |
| 62 | burr_config: dict = None, |
| 63 | graph_name: str = "Custom", |
| 64 | ): |
| 65 | self.nodes = nodes |
| 66 | self.raw_edges = edges |
| 67 | self.edges = self._create_edges(set(edges)) |
| 68 | self.entry_point = entry_point.node_name |
| 69 | self.graph_name = graph_name |
| 70 | self.initial_state = {} |
| 71 | self.callback_manager = CustomLLMCallbackManager() |
| 72 | |
| 73 | if nodes[0].node_name != entry_point.node_name: |
| 74 | warnings.warn( |
| 75 | "Careful! The entry point node is different from the first node in the graph." |
no outgoing calls