extend() — langchain Function Reference
Architecture documentation for the extend() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6764536f_15b8_5436_aa1a_53ff3f1956c2["extend()"] 646f3bb5_a594_563e_cfbf_e18bdc9efb90["Graph"] 6764536f_15b8_5436_aa1a_53ff3f1956c2 -->|defined in| 646f3bb5_a594_563e_cfbf_e18bdc9efb90 06f839e9_c953_ef45_72b3_7929f39522ed["is_uuid()"] 6764536f_15b8_5436_aa1a_53ff3f1956c2 -->|calls| 06f839e9_c953_ef45_72b3_7929f39522ed 202074c8_de09_73dd_415c_edea3bae12f1["first_node()"] 6764536f_15b8_5436_aa1a_53ff3f1956c2 -->|calls| 202074c8_de09_73dd_415c_edea3bae12f1 6b97cc3d_1205_0325_4d44_e903570471b2["last_node()"] 6764536f_15b8_5436_aa1a_53ff3f1956c2 -->|calls| 6b97cc3d_1205_0325_4d44_e903570471b2 3db09069_0f77_1402_7f96_14d549abbd03["copy()"] 6764536f_15b8_5436_aa1a_53ff3f1956c2 -->|calls| 3db09069_0f77_1402_7f96_14d549abbd03 style 6764536f_15b8_5436_aa1a_53ff3f1956c2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 384–420
def extend(
self, graph: Graph, *, prefix: str = ""
) -> tuple[Node | None, Node | None]:
"""Add all nodes and edges from another graph.
Note this doesn't check for duplicates, nor does it connect the graphs.
Args:
graph: The graph to add.
prefix: The prefix to add to the node ids.
Returns:
A tuple of the first and last nodes of the subgraph.
"""
if all(is_uuid(node.id) for node in graph.nodes.values()):
prefix = ""
def prefixed(id_: str) -> str:
return f"{prefix}:{id_}" if prefix else id_
# prefix each node
self.nodes.update(
{prefixed(k): v.copy(id=prefixed(k)) for k, v in graph.nodes.items()}
)
# prefix each edge's source and target
self.edges.extend(
[
edge.copy(source=prefixed(edge.source), target=prefixed(edge.target))
for edge in graph.edges
]
)
# return (prefixed) first and last nodes of the subgraph
first, last = graph.first_node(), graph.last_node()
return (
first.copy(id=prefixed(first.id)) if first else None,
last.copy(id=prefixed(last.id)) if last else None,
)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does extend() do?
extend() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is extend() defined?
extend() is defined in libs/core/langchain_core/runnables/graph.py at line 384.
What does extend() call?
extend() calls 4 function(s): copy, first_node, is_uuid, last_node.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free