Context Compaction question #3374
-
|
Hi everyone, Quick question. I'm trying to use the Context Compaction feature (google-adk 1.17.0), and defined the agents in the following way: However, when checking the Cloud Run logs for the container running the ADK, I can see the follwoing entries: Info: future: <Task finished name='Task-2309' coro=<_run_compaction_for_sliding_window() done, defined at /usr/local/lib/python3.13/site-packages/google/adk/apps/compaction.py:27> exception=AttributeError("'SequentialAgent' object has no attribute 'canonical_model'")> Error: File "/usr/local/lib/python3.13/site-packages/google/adk/apps/compaction.py", line 186, in _run_compaction_for_sliding_window Is there any errors on how I am defining the App with EventsCompactionConfig? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: The Thank you for your question. I can see you're running into an issue where the context compaction process is unable to find a language model. Why the Error HappensThe context compaction feature works by summarizing past events into a condensed form. This summarization is an LLM-powered operation. By default, the system tries to get the required LLM from your In your setup, the How to Fix ItTo resolve this, you can explicitly provide a model for the compaction process. This is done by creating an Here is your code, modified with the solution: from google.adk.apps.app import App, EventsCompactionConfig
from google.adk.apps.llm_event_summarizer import LlmEventSummarizer
from google.adk.models import Gemini
from google.adk.agents import SequentialAgent #, other agent types
# Assuming agent_parallel_main and agent_synthesizer are defined
# agent_parallel_main = ...
# agent_synthesizer = ...
# 1. Define the agent
root_agent = SequentialAgent(
name="root", sub_agents=[agent_parallel_main, agent_synthesizer]
)
# 2. Create a summarizer with a specific model for compaction.
# This model will be used to summarize the events.
compaction_summarizer = LlmEventSummarizer(
llm=Gemini(model="gemini-1.5-flash") # Or another model of your choice
)
# 3. Create an App instance, passing the custom summarizer in the config.
main_app = App(
name='myApp',
root_agent=root_agent,
events_compaction_config=EventsCompactionConfig(
compaction_interval=3,
overlap_size=1,
summarizer=compaction_summarizer # Pass the summarizer here
),
)
# 4. Export the app for use in the main.py file.
app = main_appBy providing a You can find more details on this in the official documentation. [1] Hope this helps! |
Beta Was this translation helpful? Give feedback.
Response from ADK Answering Agent (experimental, answer may be inaccurate)
TLDR: The
AttributeErroroccurs because yourroot_agentis aSequentialAgent, which does not have a language model (canonical_model) attached to it. The context compaction feature requires a model to summarize events. To fix this, you need to explicitly provide a summarizer with a designated model within yourEventsCompactionConfig.Hi @mmarzol-hatchworks,
Thank you for your question. I can see you're running into an issue where the context compaction process is unable to find a language model.
Why the Error Happens
The context compaction feature works by summarizing past events into a condensed form. This summari…