langchain_core.runnables.graph
.Graph¶
- class langchain_core.runnables.graph.Graph(nodes: ~typing.Dict[str, ~langchain_core.runnables.graph.Node] = <factory>, edges: ~typing.List[~langchain_core.runnables.graph.Edge] = <factory>)[source]¶
Graph of nodes and edges.
Attributes
nodes
edges
Methods
__init__
([nodes, edges])add_edge
(source, target[, data])Add an edge to the graph and return it.
add_node
(data[, id])Add a node to the graph and return it.
draw_png
()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.
to_json
()Convert the graph to a JSON-serializable format.
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_edge(source: Node, target: Node, data: Optional[str] = None) Edge [source]¶
Add an edge to the graph and return it.
- add_node(data: Union[Type[BaseModel], RunnableType], id: Optional[str] = None) Node [source]¶
Add a node to the graph and return it.
- draw_png(output_file_path: str, fontname: Optional[str] = None, labels: Optional[LabelsDict] = None) None [source]¶
- draw_png(output_file_path: None, fontname: Optional[str] = None, labels: Optional[LabelsDict] = None) bytes
- 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.
- Parameters
graph (Graph) –
- Return type
None
- 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.
- Return type
Optional[Node]
- 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.
- Return type
Optional[Node]
- remove_node(node: Node) None [source]¶
Remove a node from the graphm and all edges connected to it.
- Parameters
node (Node) –
- Return type
None
- to_json() Dict[str, List[Dict[str, Any]]] [source]¶
Convert the graph to a JSON-serializable format.
- Return type
Dict[str, List[Dict[str, Any]]]