_find_safe_cutoff() — langchain Function Reference
Architecture documentation for the _find_safe_cutoff() function in summarization.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD d7f278f1_55ee_3351_0744_37d80b5a183d["_find_safe_cutoff()"] a622f56b_f697_966d_5bc7_095699ccca34["SummarizationMiddleware"] d7f278f1_55ee_3351_0744_37d80b5a183d -->|defined in| a622f56b_f697_966d_5bc7_095699ccca34 1de03e59_b58a_edd7_ef83_95d7ab3cd1da["_determine_cutoff_index()"] 1de03e59_b58a_edd7_ef83_95d7ab3cd1da -->|calls| d7f278f1_55ee_3351_0744_37d80b5a183d 6bd2bf47_a4ef_fe6f_a2a2_89f8125a4eaa["_find_safe_cutoff_point()"] d7f278f1_55ee_3351_0744_37d80b5a183d -->|calls| 6bd2bf47_a4ef_fe6f_a2a2_89f8125a4eaa style d7f278f1_55ee_3351_0744_37d80b5a183d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/summarization.py lines 537–550
def _find_safe_cutoff(self, messages: list[AnyMessage], messages_to_keep: int) -> int:
"""Find safe cutoff point that preserves AI/Tool message pairs.
Returns the index where messages can be safely cut without separating
related AI and Tool messages. Returns `0` if no safe cutoff is found.
This is aggressive with summarization - if the target cutoff lands in the
middle of tool messages, we advance past all of them (summarizing more).
"""
if len(messages) <= messages_to_keep:
return 0
target_cutoff = len(messages) - messages_to_keep
return self._find_safe_cutoff_point(messages, target_cutoff)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _find_safe_cutoff() do?
_find_safe_cutoff() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/summarization.py.
Where is _find_safe_cutoff() defined?
_find_safe_cutoff() is defined in libs/langchain_v1/langchain/agents/middleware/summarization.py at line 537.
What does _find_safe_cutoff() call?
_find_safe_cutoff() calls 1 function(s): _find_safe_cutoff_point.
What calls _find_safe_cutoff()?
_find_safe_cutoff() is called by 1 function(s): _determine_cutoff_index.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free