_last_node() — langchain Function Reference
Architecture documentation for the _last_node() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 6607eba9_2327_f10b_2f7a_81bdd9ce1d84["_last_node()"] 81a6280b_4752_84db_f1fa_1a3b8040d481["graph.py"] 6607eba9_2327_f10b_2f7a_81bdd9ce1d84 -->|defined in| 81a6280b_4752_84db_f1fa_1a3b8040d481 6b97cc3d_1205_0325_4d44_e903570471b2["last_node()"] 6b97cc3d_1205_0325_4d44_e903570471b2 -->|calls| 6607eba9_2327_f10b_2f7a_81bdd9ce1d84 5ce5505c_4a08_f190_13f7_65b75fa4fde9["trim_last_node()"] 5ce5505c_4a08_f190_13f7_65b75fa4fde9 -->|calls| 6607eba9_2327_f10b_2f7a_81bdd9ce1d84 style 6607eba9_2327_f10b_2f7a_81bdd9ce1d84 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 724–739
def _last_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
"""Find the single node that is not a source of any edge.
Exclude nodes/targets 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 destination.
"""
sources = {edge.source for edge in graph.edges if edge.target not in exclude}
found: list[Node] = [
node
for node in graph.nodes.values()
if node.id not in exclude and node.id not in sources
]
return found[0] if len(found) == 1 else None
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _last_node() do?
_last_node() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is _last_node() defined?
_last_node() is defined in libs/core/langchain_core/runnables/graph.py at line 724.
What calls _last_node()?
_last_node() is called by 2 function(s): last_node, trim_last_node.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free