langchain_core.runnables.graph
.Graph¶
- class langchain_core.runnables.graph.Graph(nodes: 'Dict[str, Node]' = <factory>, edges: 'List[Edge]' = <factory>)[source]¶
Attributes
nodes
edges
Methods
__init__
([nodes, edges])add_edge
(source, target)Add an edge to the graph and return it.
add_node
(data)Add a node to the graph and return it.
extend
(graph)Add all nodes and edges from another graph.
Find the single node that is not a target of any edge.
Find the single node that is not a source of any edge.
next_id
()remove_node
(node)Remove a node from the graphm and all edges connected to it.
Remove the first node if it exists and has a single outgoing edge, ie.
Remove the last node if it exists and has a single incoming edge, ie.
- __init__(nodes: ~typing.Dict[str, ~langchain_core.runnables.graph.Node] = <factory>, edges: ~typing.List[~langchain_core.runnables.graph.Edge] = <factory>) None ¶
- add_node(data: Union[Type[BaseModel], RunnableType]) Node [source]¶
Add a node to the graph and return it.
- extend(graph: Graph) None [source]¶
Add all nodes and edges from another graph. Note this doesn’t check for duplicates, nor does it connect the graphs.
- first_node() Optional[Node] [source]¶
Find the single node that is not a target of any edge. If there is no such node, or there are multiple, return None. When drawing the graph this node would be the origin.
- last_node() Optional[Node] [source]¶
Find the single node that is not a source of any edge. If there is no such node, or there are multiple, return None. When drawing the graph this node would be the destination.
- remove_node(node: Node) None [source]¶
Remove a node from the graphm and all edges connected to it.