Home / Class/ SummarizerMixin Class — langchain Architecture

SummarizerMixin Class — langchain Architecture

Architecture documentation for the SummarizerMixin class in summary.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  b59972c7_2658_48b0_f600_7b1f592481af["SummarizerMixin"]
  3460fa37_4fa8_1998_2c3c_01d1d3814b73["summary.py"]
  b59972c7_2658_48b0_f600_7b1f592481af -->|defined in| 3460fa37_4fa8_1998_2c3c_01d1d3814b73
  440abe33_20df_ee02_d771_d5bb5d39241f["predict_new_summary()"]
  b59972c7_2658_48b0_f600_7b1f592481af -->|method| 440abe33_20df_ee02_d771_d5bb5d39241f
  bd542e1b_cbff_eace_acc7_16110f14f487["apredict_new_summary()"]
  b59972c7_2658_48b0_f600_7b1f592481af -->|method| bd542e1b_cbff_eace_acc7_16110f14f487

Relationship Graph

Source Code

libs/langchain/langchain_classic/memory/summary.py lines 27–80

class SummarizerMixin(BaseModel):
    """Mixin for summarizer."""

    human_prefix: str = "Human"
    ai_prefix: str = "AI"
    llm: BaseLanguageModel
    prompt: BasePromptTemplate = SUMMARY_PROMPT
    summary_message_cls: type[BaseMessage] = SystemMessage

    def predict_new_summary(
        self,
        messages: list[BaseMessage],
        existing_summary: str,
    ) -> str:
        """Predict a new summary based on the messages and existing summary.

        Args:
            messages: List of messages to summarize.
            existing_summary: Existing summary to build upon.

        Returns:
            A new summary string.
        """
        new_lines = get_buffer_string(
            messages,
            human_prefix=self.human_prefix,
            ai_prefix=self.ai_prefix,
        )

        chain = LLMChain(llm=self.llm, prompt=self.prompt)
        return chain.predict(summary=existing_summary, new_lines=new_lines)

    async def apredict_new_summary(
        self,
        messages: list[BaseMessage],
        existing_summary: str,
    ) -> str:
        """Predict a new summary based on the messages and existing summary.

        Args:
            messages: List of messages to summarize.
            existing_summary: Existing summary to build upon.

        Returns:
            A new summary string.
        """
        new_lines = get_buffer_string(
            messages,
            human_prefix=self.human_prefix,
            ai_prefix=self.ai_prefix,
        )

        chain = LLMChain(llm=self.llm, prompt=self.prompt)
        return await chain.apredict(summary=existing_summary, new_lines=new_lines)

Frequently Asked Questions

What is the SummarizerMixin class?
SummarizerMixin is a class in the langchain codebase, defined in libs/langchain/langchain_classic/memory/summary.py.
Where is SummarizerMixin defined?
SummarizerMixin is defined in libs/langchain/langchain_classic/memory/summary.py at line 27.

Analyze Your Own Codebase

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

Try Supermodel Free