Skip to content

Commit f1abdb1

Browse files
hangfeicopybara-github
authored andcommitted
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
1 parent 68402bd commit f1abdb1

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed

src/google/adk/apps/sliding_window_compactor.py renamed to src/google/adk/apps/llm_event_summarizer.py

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,23 @@
2727
from .base_events_compactor import BaseEventsCompactor
2828

2929

30-
class SlidingWindowCompactor(BaseEventsCompactor):
31-
"""A summarizer for Sliding Window Compaction logic in Runner.
32-
33-
This compactor works with ADK runner to provide sliding window compaction.
34-
The runner uses `compaction_invocation_threshold` and `overlap_size`
35-
configured in `EventsCompactionConfig` on the `App` to determine when to
36-
trigger compaction and which events to compact. This class performs
37-
summarization of events passed by the runner.
38-
39-
The compaction process is controlled by two parameters read by the Runner from
40-
`EventsCompactionConfig`:
41-
1. `compaction_invocation_threshold`: The number of *new* user-initiated
42-
invocations that, once fully
43-
represented in the session's events, will trigger a compaction.
44-
2. `overlap_size`: The number of preceding invocations to include from the
45-
end of the last
46-
compacted range. This creates an overlap between consecutive compacted
47-
summaries,
48-
maintaining context.
49-
50-
When `Runner` determines compaction is needed based on
51-
`compaction_invocation_threshold`,
52-
it selects a range of events based on `overlap_size` and passes them to
53-
`maybe_compact_events` for summarization into a `CompactedEvent`.
54-
This `CompactedEvent` is then appended to the session by the `Runner`.
30+
class LlmEventSummarizer(BaseEventsCompactor):
31+
"""An LLM-based event summarizer for sliding window compaction.
32+
33+
This class is responsible for summarizing a provided list of events into a
34+
single compacted event. It is designed to be used as part of a sliding window
35+
compaction process.
36+
37+
The actual logic for determining *when* to trigger compaction and *which*
38+
events form the sliding window (based on parameters like
39+
`compaction_invocation_threshold` and `overlap_size` from
40+
`EventsCompactionConfig`) is handled by an external component, such as an ADK
41+
"Runner". This compactor focuses solely on generating a summary of the events
42+
it receives.
43+
44+
When `maybe_compact_events` is called with a list of events, this class
45+
formats the events, generates a summary using an LLM, and returns a new
46+
`Event` containing the summary within an `EventCompaction`.
5547
"""
5648

5749
_DEFAULT_PROMPT_TEMPLATE = (
@@ -68,7 +60,7 @@ def __init__(
6860
llm: BaseLlm,
6961
prompt_template: Optional[str] = None,
7062
):
71-
"""Initializes the SlidingWindowCompactor.
63+
"""Initializes the LlmEventSummarizer.
7264
7365
Args:
7466
llm: The LLM used for summarization.

src/google/adk/runners.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import warnings
2929

3030
from google.adk.apps.compaction import _run_compaction_for_sliding_window
31-
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor
3231
from google.genai import types
3332

3433
from .agents.active_streaming_tool import ActiveStreamingTool

tests/unittests/apps/test_compaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from google.adk.apps.app import App
2121
from google.adk.apps.app import EventsCompactionConfig
2222
from google.adk.apps.compaction import _run_compaction_for_sliding_window
23-
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor
23+
from google.adk.apps.llm_event_summarizer import LlmEventSummarizer
2424
from google.adk.events.event import Event
2525
from google.adk.events.event_actions import EventActions
2626
from google.adk.events.event_actions import EventCompaction
@@ -38,7 +38,7 @@ class TestCompaction(unittest.IsolatedAsyncioTestCase):
3838

3939
def setUp(self):
4040
self.mock_session_service = AsyncMock(spec=BaseSessionService)
41-
self.mock_compactor = AsyncMock(spec=SlidingWindowCompactor)
41+
self.mock_compactor = AsyncMock(spec=LlmEventSummarizer)
4242

4343
def _create_event(
4444
self, timestamp: float, invocation_id: str, text: str

tests/unittests/apps/test_sliding_window_compactor.py renamed to tests/unittests/apps/test_llm_event_summarizer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from unittest.mock import AsyncMock
1717
from unittest.mock import Mock
1818

19-
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor
19+
from google.adk.apps.llm_event_summarizer import LlmEventSummarizer
2020
from google.adk.events.event import Event
2121
from google.adk.events.event_actions import EventActions
2222
from google.adk.events.event_actions import EventCompaction
@@ -32,12 +32,12 @@
3232
@pytest.mark.parametrize(
3333
'env_variables', ['GOOGLE_AI', 'VERTEX'], indirect=True
3434
)
35-
class TestSlidingWindowCompactor(unittest.IsolatedAsyncioTestCase):
35+
class TestLlmEventSummarizer(unittest.IsolatedAsyncioTestCase):
3636

3737
def setUp(self):
3838
self.mock_llm = AsyncMock(spec=BaseLlm)
3939
self.mock_llm.model = 'test-model'
40-
self.compactor = SlidingWindowCompactor(llm=self.mock_llm)
40+
self.compactor = LlmEventSummarizer(llm=self.mock_llm)
4141

4242
def _create_event(
4343
self, timestamp: float, text: str, author: str = 'user'

0 commit comments

Comments
 (0)