add_edge() — langchain Function Reference
Architecture documentation for the add_edge() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f1aa2cc8_a959_f2b6_f36e_f96286c417ed["add_edge()"] 646f3bb5_a594_563e_cfbf_e18bdc9efb90["Graph"] f1aa2cc8_a959_f2b6_f36e_f96286c417ed -->|defined in| 646f3bb5_a594_563e_cfbf_e18bdc9efb90 style f1aa2cc8_a959_f2b6_f36e_f96286c417ed fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 351–382
def add_edge(
self,
source: Node,
target: Node,
data: Stringifiable | None = None,
conditional: bool = False, # noqa: FBT001,FBT002
) -> Edge:
"""Add an edge to the graph and return it.
Args:
source: The source node of the edge.
target: The target node of the edge.
data: Optional data associated with the edge.
conditional: Whether the edge is conditional.
Returns:
The edge that was added to the graph.
Raises:
ValueError: If the source or target node is not in the graph.
"""
if source.id not in self.nodes:
msg = f"Source node {source.id} not in graph"
raise ValueError(msg)
if target.id not in self.nodes:
msg = f"Target node {target.id} not in graph"
raise ValueError(msg)
edge = Edge(
source=source.id, target=target.id, data=data, conditional=conditional
)
self.edges.append(edge)
return edge
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does add_edge() do?
add_edge() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is add_edge() defined?
add_edge() is defined in libs/core/langchain_core/runnables/graph.py at line 351.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free