-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Description
I am trying to deploy an ADK agent in Agent Engine using VertexAiSessionService.
The setup was working correctly before introducing EventsCompactionConfig and ContextCacheConfig.
To enable conversation history compression and caching, I wrapped my agent using google.adk.apps.App and provided the compaction and cache configurations. After doing this, I started encountering a pydantic ValidationError during invocation.
My main goal is to control conversation history growth by compressing or filtering past events (to limit token usage).
Code Snippet
from vertexai import agent_engines
from google.adk.apps.app import EventsCompactionConfig
from google.adk.agents.context_cache_config import ContextCacheConfig
from google.adk.sessions import VertexAiSessionService
from agents.root_agent.agent import root_agent
from google.adk.apps import App
def session_service_builder(**kwargs):
return VertexAiSessionService(location="asia-south1")
google_adk_app = App(
root_agent=root_agent,
name="root_agent",
events_compaction_config=EventsCompactionConfig(
compaction_interval=3, # Trigger compaction every 3 new invocations
overlap_size=1
),
context_cache_config=ContextCacheConfig(
min_tokens=2048, # Minimum tokens to trigger caching
ttl_seconds=600, # Store for up to 10 minutes
cache_intervals=5, # Refresh after 5 uses
)
)
app = agent_engines.AdkApp(
agent=google_adk_app,
enable_tracing=True,
session_service_builder=session_service_builder
)Error
Traceback (most recent call last):
File "/code/app/api/factory/python_file_api_builder.py", line 473, in _async_stream_json_generator
async for chunk in output:
File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/vertexai/agent_engines/templates/adk.py", line 1058, in async_stream_query
async for event in events_async:
File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 561, in run_async
async for event in agen:
File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 529, in _run_with_trace
invocation_context = await self._setup_context_for_new_invocation(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 1275, in _setup_context_for_new_invocation
invocation_context = self._new_invocation_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/google/adk/runners.py", line 1405, in _new_invocation_context
return InvocationContext(
^^^^^^^^^^^^^^^^^^
File "/home/appuser/.cache/pypoetry/virtualenvs/reasoning-engine-assembly-service-MATOk_fk-py3.12/lib/python3.12/site-packages/pydantic/main.py", line 253, in __init__
validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for InvocationContext
Full traceback indicates failure during _new_invocation_context inside google.adk.runners.
Questions
-
Does
VertexAiSessionServicecurrently supportEventsCompactionConfigandContextCacheConfig? -
Is there any incompatibility between
google.adk.apps.Appwrapping andagent_engines.AdkApp? -
If context caching/compaction is not supported with
VertexAiSessionService, what is the recommended way to:- Compress conversation history?
- Limit token growth?
- Filter past events before sending to the model?
Expected Behavior
The agent should support:
- Automatic event compaction
- Context caching
- Controlled conversation history growth
while using VertexAiSessionService inside Agent Engine.