add_node() — langchain Function Reference
Architecture documentation for the add_node() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5bdca968_0e0c_d6c2_7bf4_f1990e3d1d78["add_node()"] 646f3bb5_a594_563e_cfbf_e18bdc9efb90["Graph"] 5bdca968_0e0c_d6c2_7bf4_f1990e3d1d78 -->|defined in| 646f3bb5_a594_563e_cfbf_e18bdc9efb90 417755a5_d458_ad2e_a8b0_7b8e1dcb0c46["next_id()"] 5bdca968_0e0c_d6c2_7bf4_f1990e3d1d78 -->|calls| 417755a5_d458_ad2e_a8b0_7b8e1dcb0c46 e36afb73_0117_69fe_01c8_c476692e8baa["node_data_str()"] 5bdca968_0e0c_d6c2_7bf4_f1990e3d1d78 -->|calls| e36afb73_0117_69fe_01c8_c476692e8baa style 5bdca968_0e0c_d6c2_7bf4_f1990e3d1d78 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 312–338
def add_node(
self,
data: type[BaseModel] | RunnableType | None,
id: str | None = None,
*,
metadata: dict[str, Any] | None = None,
) -> Node:
"""Add a node to the graph and return it.
Args:
data: The data of the node.
id: The id of the node.
metadata: Optional metadata for the node.
Returns:
The node that was added to the graph.
Raises:
ValueError: If a node with the same id already exists.
"""
if id is not None and id in self.nodes:
msg = f"Node with id {id} already exists"
raise ValueError(msg)
id_ = id or self.next_id()
node = Node(id=id_, data=data, metadata=metadata, name=node_data_str(id_, data))
self.nodes[node.id] = node
return node
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does add_node() do?
add_node() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is add_node() defined?
add_node() is defined in libs/core/langchain_core/runnables/graph.py at line 312.
What does add_node() call?
add_node() calls 2 function(s): next_id, node_data_str.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free