llm_context_summarizer

This module defines a summarizer for managing LLM context summarization.

class pipecat.processors.aggregators.llm_context_summarizer.SummaryAppliedEvent(original_message_count: int, new_message_count: int, summarized_message_count: int, preserved_message_count: int)[source]

Bases: object

Event data emitted when context summarization completes successfully.

Parameters:
  • original_message_count – Number of messages before summarization.

  • new_message_count – Number of messages after summarization.

  • summarized_message_count – Number of messages that were compressed into the summary.

  • preserved_message_count – Number of recent messages preserved uncompressed.

original_message_count: int
new_message_count: int
summarized_message_count: int
preserved_message_count: int
class pipecat.processors.aggregators.llm_context_summarizer.LLMContextSummarizer(*, context: LLMContext, config: LLMAutoContextSummarizationConfig | None = None, auto_trigger: bool = True)[source]

Bases: BaseObject

Summarizer for managing LLM context summarization.

This class manages context summarization, either automatically when token or message limits are reached, or on-demand when an LLMSummarizeContextFrame is received. It monitors the LLM context size, triggers summarization requests, and applies the results to compress conversation history.

When auto_trigger=True (the default), summarization is triggered automatically based on the configured thresholds in LLMAutoContextSummarizationConfig. When auto_trigger=False, threshold checks are skipped and summarization only happens when an LLMSummarizeContextFrame is explicitly pushed into the pipeline.

Both modes can coexist: set auto_trigger=True and also push LLMSummarizeContextFrame at any time to force an immediate summarization (subject to the _summarization_in_progress guard).

Event handlers available:

  • on_request_summarization: Emitted when summarization should be triggered.

    The aggregator should broadcast this frame to the LLM service.

  • on_summary_applied: Emitted after a summary has been successfully applied

    to the context. Receives a SummaryAppliedEvent with metrics about the compression.

Example:

@summarizer.event_handler("on_request_summarization")
async def on_request_summarization(summarizer, frame: LLMContextSummaryRequestFrame):
    await aggregator.broadcast_frame(
        LLMContextSummaryRequestFrame,
        request_id=frame.request_id,
        context=frame.context,
        ...
    )

@summarizer.event_handler("on_summary_applied")
async def on_summary_applied(summarizer, event: SummaryAppliedEvent):
    logger.info(f"Compressed {event.original_message_count} -> {event.new_message_count} messages")
__init__(*, context: LLMContext, config: LLMAutoContextSummarizationConfig | None = None, auto_trigger: bool = True)[source]

Initialize the context summarizer.

Parameters:
  • context – The LLM context to monitor and summarize.

  • config – Auto-summarization configuration controlling both trigger thresholds and default summary generation parameters. If None, uses default LLMAutoContextSummarizationConfig values.

  • auto_trigger – Whether to automatically trigger summarization when thresholds are reached. When False, summarization only happens when an LLMSummarizeContextFrame is pushed into the pipeline. Defaults to True.

property task_manager: BaseTaskManager

Returns the configured task manager.

async setup(task_manager: BaseTaskManager)[source]

Initialize the summarizer with the given task manager.

Parameters:

task_manager – The task manager to be associated with this instance.

async cleanup()[source]

Cleanup the summarizer.

async process_frame(frame: Frame)[source]

Process an incoming frame to detect when summarization is needed.

Parameters:

frame – The frame to be processed.