_first_node() — langchain Function Reference
Architecture documentation for the _first_node() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c2fe47ba_c1ff_8826_55de_cd87be044850["_first_node()"] 81a6280b_4752_84db_f1fa_1a3b8040d481["graph.py"] c2fe47ba_c1ff_8826_55de_cd87be044850 -->|defined in| 81a6280b_4752_84db_f1fa_1a3b8040d481 202074c8_de09_73dd_415c_edea3bae12f1["first_node()"] 202074c8_de09_73dd_415c_edea3bae12f1 -->|calls| c2fe47ba_c1ff_8826_55de_cd87be044850 600fa640_4465_baee_3ef3_0c1fda5bf94b["trim_first_node()"] 600fa640_4465_baee_3ef3_0c1fda5bf94b -->|calls| c2fe47ba_c1ff_8826_55de_cd87be044850 style c2fe47ba_c1ff_8826_55de_cd87be044850 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 706–721
def _first_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
"""Find the single node that is not a target of any edge.
Exclude nodes/sources with IDs in the exclude list.
If there is no such node, or there are multiple, return `None`.
When drawing the graph, this node would be the origin.
"""
targets = {edge.target for edge in graph.edges if edge.source not in exclude}
found: list[Node] = [
node
for node in graph.nodes.values()
if node.id not in exclude and node.id not in targets
]
return found[0] if len(found) == 1 else None
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _first_node() do?
_first_node() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is _first_node() defined?
_first_node() is defined in libs/core/langchain_core/runnables/graph.py at line 706.
What calls _first_node()?
_first_node() is called by 2 function(s): first_node, trim_first_node.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free