Add a node to the graph and return it.
(
self, data: Union[Type[BaseModel], RunnableType], id: Optional[str] = None
)
| 237 | return uuid4().hex |
| 238 | |
| 239 | def add_node( |
| 240 | self, data: Union[Type[BaseModel], RunnableType], id: Optional[str] = None |
| 241 | ) -> Node: |
| 242 | """Add a node to the graph and return it.""" |
| 243 | if id is not None and id in self.nodes: |
| 244 | raise ValueError(f"Node with id {id} already exists") |
| 245 | node = Node(id=id or self.next_id(), data=data) |
| 246 | self.nodes[node.id] = node |
| 247 | return node |
| 248 | |
| 249 | def remove_node(self, node: Node) -> None: |
| 250 | """Remove a node from the graphm and all edges connected to it.""" |