mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Rename SlidingWindowCompactor to LlmEventSummarizer and refine its docstring
The class is now named `LlmEventSummarizer` to better reflect that its primary function is to use an LLM to summarize events. The docstring has been updated to clarify that this class is responsible *only* for the LLM-based summarization of a given set of events, while the logic for determining *when* and *which* events form the sliding window is handled by an external component, such as an ADK Runner. PiperOrigin-RevId: 815976264
This commit is contained in:
committed by
Copybara-Service
parent
68402bda49
commit
f1abdb1938
+15
-23
@@ -27,31 +27,23 @@ from ..models.llm_request import LlmRequest
|
||||
from .base_events_compactor import BaseEventsCompactor
|
||||
|
||||
|
||||
class SlidingWindowCompactor(BaseEventsCompactor):
|
||||
"""A summarizer for Sliding Window Compaction logic in Runner.
|
||||
class LlmEventSummarizer(BaseEventsCompactor):
|
||||
"""An LLM-based event summarizer for sliding window compaction.
|
||||
|
||||
This compactor works with ADK runner to provide sliding window compaction.
|
||||
The runner uses `compaction_invocation_threshold` and `overlap_size`
|
||||
configured in `EventsCompactionConfig` on the `App` to determine when to
|
||||
trigger compaction and which events to compact. This class performs
|
||||
summarization of events passed by the runner.
|
||||
This class is responsible for summarizing a provided list of events into a
|
||||
single compacted event. It is designed to be used as part of a sliding window
|
||||
compaction process.
|
||||
|
||||
The compaction process is controlled by two parameters read by the Runner from
|
||||
`EventsCompactionConfig`:
|
||||
1. `compaction_invocation_threshold`: The number of *new* user-initiated
|
||||
invocations that, once fully
|
||||
represented in the session's events, will trigger a compaction.
|
||||
2. `overlap_size`: The number of preceding invocations to include from the
|
||||
end of the last
|
||||
compacted range. This creates an overlap between consecutive compacted
|
||||
summaries,
|
||||
maintaining context.
|
||||
The actual logic for determining *when* to trigger compaction and *which*
|
||||
events form the sliding window (based on parameters like
|
||||
`compaction_invocation_threshold` and `overlap_size` from
|
||||
`EventsCompactionConfig`) is handled by an external component, such as an ADK
|
||||
"Runner". This compactor focuses solely on generating a summary of the events
|
||||
it receives.
|
||||
|
||||
When `Runner` determines compaction is needed based on
|
||||
`compaction_invocation_threshold`,
|
||||
it selects a range of events based on `overlap_size` and passes them to
|
||||
`maybe_compact_events` for summarization into a `CompactedEvent`.
|
||||
This `CompactedEvent` is then appended to the session by the `Runner`.
|
||||
When `maybe_compact_events` is called with a list of events, this class
|
||||
formats the events, generates a summary using an LLM, and returns a new
|
||||
`Event` containing the summary within an `EventCompaction`.
|
||||
"""
|
||||
|
||||
_DEFAULT_PROMPT_TEMPLATE = (
|
||||
@@ -68,7 +60,7 @@ class SlidingWindowCompactor(BaseEventsCompactor):
|
||||
llm: BaseLlm,
|
||||
prompt_template: Optional[str] = None,
|
||||
):
|
||||
"""Initializes the SlidingWindowCompactor.
|
||||
"""Initializes the LlmEventSummarizer.
|
||||
|
||||
Args:
|
||||
llm: The LLM used for summarization.
|
||||
@@ -28,7 +28,6 @@ from typing import Optional
|
||||
import warnings
|
||||
|
||||
from google.adk.apps.compaction import _run_compaction_for_sliding_window
|
||||
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor
|
||||
from google.genai import types
|
||||
|
||||
from .agents.active_streaming_tool import ActiveStreamingTool
|
||||
|
||||
@@ -20,7 +20,7 @@ from google.adk.agents.base_agent import BaseAgent
|
||||
from google.adk.apps.app import App
|
||||
from google.adk.apps.app import EventsCompactionConfig
|
||||
from google.adk.apps.compaction import _run_compaction_for_sliding_window
|
||||
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor
|
||||
from google.adk.apps.llm_event_summarizer import LlmEventSummarizer
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.events.event_actions import EventActions
|
||||
from google.adk.events.event_actions import EventCompaction
|
||||
@@ -38,7 +38,7 @@ class TestCompaction(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mock_session_service = AsyncMock(spec=BaseSessionService)
|
||||
self.mock_compactor = AsyncMock(spec=SlidingWindowCompactor)
|
||||
self.mock_compactor = AsyncMock(spec=LlmEventSummarizer)
|
||||
|
||||
def _create_event(
|
||||
self, timestamp: float, invocation_id: str, text: str
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@ import unittest
|
||||
from unittest.mock import AsyncMock
|
||||
from unittest.mock import Mock
|
||||
|
||||
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor
|
||||
from google.adk.apps.llm_event_summarizer import LlmEventSummarizer
|
||||
from google.adk.events.event import Event
|
||||
from google.adk.events.event_actions import EventActions
|
||||
from google.adk.events.event_actions import EventCompaction
|
||||
@@ -32,12 +32,12 @@ import pytest
|
||||
@pytest.mark.parametrize(
|
||||
'env_variables', ['GOOGLE_AI', 'VERTEX'], indirect=True
|
||||
)
|
||||
class TestSlidingWindowCompactor(unittest.IsolatedAsyncioTestCase):
|
||||
class TestLlmEventSummarizer(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.mock_llm = AsyncMock(spec=BaseLlm)
|
||||
self.mock_llm.model = 'test-model'
|
||||
self.compactor = SlidingWindowCompactor(llm=self.mock_llm)
|
||||
self.compactor = LlmEventSummarizer(llm=self.mock_llm)
|
||||
|
||||
def _create_event(
|
||||
self, timestamp: float, text: str, author: str = 'user'
|
||||
Reference in New Issue
Block a user