Skip to content

Compaction Metadata Causes AttributeError in v1.21+ #4082

@nicwang119

Description

@nicwang119

Describe the issue
When using App(..., events_compaction_config=...) with ADK v1.21.0+, the session crashes after compaction is triggered (e.g., on the 4th message if compaction_interval=3).
The error is caused by event.actions.compaction being inserted as a raw dict, while downstream ADK code expects a structured object with attributes like .start_timestamp.

This leads to:

AttributeError: 'dict' object has no attribute 'start_timestamp'

To Reproduce

  1. Install google-adk==1.21.0 or later
  2. Run the following code:
from google.adk.agents import LlmAgent
from google.adk.models.google_llm import Gemini
from google.adk.app import App
from google.adk.runners import Runner
from google.adk.sessions import DatabaseSessionService
from google.adk.config import EventsCompactionConfig

chatbot_agent = LlmAgent(
    model=Gemini(model="gemini-2.5-flash-lite"),
    name="text_chat_bot",
    description="Agent with memory and compaction",
)

research_app_compacting = App(
    name="research_app_compacting",
    root_agent=chatbot_agent,
    events_compaction_config=EventsCompactionConfig(
        compaction_interval=3,
        overlap_size=1,
    ),
)

db_url = "sqlite+aiosqlite:///my_agent_data.db"
session_service = DatabaseSessionService(db_url=db_url)

research_runner_compacting = Runner(
    app=research_app_compacting,
    session_service=session_service,
)

# Run 4 turns (turn 3 triggers compaction)
async def run_session():
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 1"
    )
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 2"
    )
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 3"
    )  # compaction triggers here
    await research_runner_compacting.run_async(
        user_id="u1", session_id="compaction_demo", new_message="Turn 4"
    )  # 💥 crashes here
  1. See the error:
File ".../contents.py", line 306, in _process_compaction_events
  if compaction.start_timestamp is not None:
AttributeError: 'dict' object has no attribute 'start_timestamp'

Expected behavior
ADK should store event.actions.compaction as a structured object (e.g., CompactionAction) or automatically convert dicts to object format before accessing attributes.


Desktop (please complete the following information):

  • OS: Ubuntu (Kaggle Notebook)
  • Python version (python -V): 3.12.12
  • ADK version (pip show google-adk): 1.21.0

Model Information:

  • Are you using LiteLLM: No
  • Which model is being used: gemini-2.5-flash-lite

Screenshots

Image ---

Metadata

Metadata

Assignees

No one assigned

    Labels

    services[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions