adk-docs icon indicating copy to clipboard operation
adk-docs copied to clipboard

Getting error on sliding_window_compactor

Open vedantdere01042001-lang opened this issue 2 months ago • 5 comments

ModuleNotFoundError: Fail to load 'n_level_agent' module. No module named 'google.adk.apps.sliding_window_compactor'

from pydantic import BaseModel, Field
from typing import List
from google.adk.apps.app import App
from google.adk.apps.app import EventsCompactionConfig
from google.adk.models import Gemini
from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor

When we are importing sliding_window_compactor getting error

vedantdere01042001-lang avatar Nov 12 '25 05:11 vedantdere01042001-lang

Hello @vedantdere01042001-lang ,

The function you might be looking for is _run_compaction_for_sliding_window, located in compaction.py.

You can import it using the following line:

from google.adk.apps.compaction import _run_compaction_for_sliding_window

Please try this and let us know if it meets your requirements.

llalitkumarrr avatar Nov 12 '25 07:11 llalitkumarrr

Hi @llalitkumarrr But in the documentation they are importing it like this

from google.adk.apps.sliding_window_compactor import SlidingWindowCompactor

https://google.github.io/adk-docs/context/compaction/#define-compactor

vedantdere01042001-lang avatar Nov 13 '25 09:11 vedantdere01042001-lang

@vedantdere01042001-lang Thanks for pointing out. I see that he SlidingWindowCompactor is renamed to LlmEventSummarizer. Perhaps we should update our docs to reflect the same.

Here is the corrected code snippet. I've replaced the old SlidingWindowCompactor with the LlmEventSummarizer and configured it correctly within the EventsCompactionConfig.

from google.adk.apps.app import App, EventsCompactionConfig
from google.adk.apps.llm_event_summarizer import LlmEventSummarizer
from google.adk.models import Gemini

# Assume root_agent is already defined

# Define the AI model to be used for summarization:
summarization_llm = Gemini(model="gemini-2.5-flash")

# Create the summarizer with the custom model:
my_summarizer = LlmEventSummarizer(llm=summarization_llm)

# Configure the App with the custom summarizer and compaction settings:
app = App(
    name='my-agent',
    root_agent=root_agent,
    events_compaction_config=EventsCompactionConfig(
        summarizer=my_summarizer,
        compaction_interval=3,
        overlap_size=1
    ),
)

print("App configured successfully with custom event summarizer.")

ymodak avatar Nov 13 '25 23:11 ymodak

Thanks for reporting. @joefernandez to help update the documentation.

hangfei avatar Nov 14 '25 15:11 hangfei

When I am running an Agent getting error

Session not found: 0776d1f5-a56c-47fa-9161-316fbfe419bf

vedantdere01042001-lang avatar Nov 17 '25 03:11 vedantdere01042001-lang