trim_last_node() — langchain Function Reference
Architecture documentation for the trim_last_node() function in graph.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 5ce5505c_4a08_f190_13f7_65b75fa4fde9["trim_last_node()"] 646f3bb5_a594_563e_cfbf_e18bdc9efb90["Graph"] 5ce5505c_4a08_f190_13f7_65b75fa4fde9 -->|defined in| 646f3bb5_a594_563e_cfbf_e18bdc9efb90 6b97cc3d_1205_0325_4d44_e903570471b2["last_node()"] 5ce5505c_4a08_f190_13f7_65b75fa4fde9 -->|calls| 6b97cc3d_1205_0325_4d44_e903570471b2 1eb728cf_7631_9204_a3a2_e3d486989562["remove_node()"] 5ce5505c_4a08_f190_13f7_65b75fa4fde9 -->|calls| 1eb728cf_7631_9204_a3a2_e3d486989562 6607eba9_2327_f10b_2f7a_81bdd9ce1d84["_last_node()"] 5ce5505c_4a08_f190_13f7_65b75fa4fde9 -->|calls| 6607eba9_2327_f10b_2f7a_81bdd9ce1d84 style 5ce5505c_4a08_f190_13f7_65b75fa4fde9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/runnables/graph.py lines 494–505
def trim_last_node(self) -> None:
"""Remove the last node if it exists and has a single incoming edge.
i.e., if removing it would not leave the graph without a "last" node.
"""
last_node = self.last_node()
if (
last_node
and _last_node(self, exclude=[last_node.id])
and len({e for e in self.edges if e.target == last_node.id}) == 1
):
self.remove_node(last_node)
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does trim_last_node() do?
trim_last_node() is a function in the langchain codebase, defined in libs/core/langchain_core/runnables/graph.py.
Where is trim_last_node() defined?
trim_last_node() is defined in libs/core/langchain_core/runnables/graph.py at line 494.
What does trim_last_node() call?
trim_last_node() calls 3 function(s): _last_node, last_node, remove_node.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free