Home / Function/ aprune() — langchain Function Reference

aprune() — langchain Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  6795ba4d_a89f_491b_adce_ad14a42f7963["aprune()"]
  f7800961_f1f1_7fa8_1fe5_64c9aba0b253["ConversationSummaryBufferMemory"]
  6795ba4d_a89f_491b_adce_ad14a42f7963 -->|defined in| f7800961_f1f1_7fa8_1fe5_64c9aba0b253
  c470c907_8097_22c1_6d1f_84616428b19f["asave_context()"]
  c470c907_8097_22c1_6d1f_84616428b19f -->|calls| 6795ba4d_a89f_491b_adce_ad14a42f7963
  style 6795ba4d_a89f_491b_adce_ad14a42f7963 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/memory/summary_buffer.py lines 126–138

    async def aprune(self) -> None:
        """Asynchronously 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 = await self.apredict_new_summary(
                pruned_memory,
                self.moving_summary_buffer,
            )

Domain

Subdomains

Called By

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free