Home / Function/ prune() — langchain Function Reference

prune() — langchain Function Reference

Architecture documentation for the prune() function in summary_buffer.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  970900c9_b0e6_a6cb_7ee0_3f55359d29ec["prune()"]
  f7800961_f1f1_7fa8_1fe5_64c9aba0b253["ConversationSummaryBufferMemory"]
  970900c9_b0e6_a6cb_7ee0_3f55359d29ec -->|defined in| f7800961_f1f1_7fa8_1fe5_64c9aba0b253
  2969edee_c986_9fa2_dc7a_e44fb800b832["save_context()"]
  2969edee_c986_9fa2_dc7a_e44fb800b832 -->|calls| 970900c9_b0e6_a6cb_7ee0_3f55359d29ec
  style 970900c9_b0e6_a6cb_7ee0_3f55359d29ec fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/memory/summary_buffer.py lines 112–124

    def prune(self) -> None:
        """Prune buffer if it exceeds max token limit."""
        buffer = self.chat_memory.messages
        curr_buffer_length = self.llm.get_num_tokens_from_messages(buffer)
        if curr_buffer_length > self.max_token_limit:
            pruned_memory = []
            while curr_buffer_length > self.max_token_limit:
                pruned_memory.append(buffer.pop(0))
                curr_buffer_length = self.llm.get_num_tokens_from_messages(buffer)
            self.moving_summary_buffer = self.predict_new_summary(
                pruned_memory,
                self.moving_summary_buffer,
            )

Domain

Subdomains

Called By

Frequently Asked Questions

What does prune() do?
prune() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/memory/summary_buffer.py.
Where is prune() defined?
prune() is defined in libs/langchain/langchain_classic/memory/summary_buffer.py at line 112.
What calls prune()?
prune() is called by 1 function(s): save_context.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free