Repository navigation
Description
🔴 Required Information
Describe the Bug:
VertexAiSessionService does not persist cache_metadata or usage_metadata fields when writing/reading Event objects to/from Agent Engine. This causes ContextCacheRequestProcessor to never find prior cache metadata, so context caching creates a new cache on every invocation instead of reusing existing ones.
Steps to Reproduce:
- Install
google-adk[eval]==1.25.1 - Configure an agent with
ContextCacheConfigin App():
app = App(
name="my_agent",
root_agent=root_agent,
context_cache_config= ContextCacheConfig( min_tokens=2048, ttl_seconds=1800, cache_intervals=10),)
- Run with in-memory sessions:
adk web— send the same prompt twice in the same session. ObservecacheMetadatain the dev UI showingcache_namereuse on the second turn. - Run with Agent Engine sessions:
adk web --session_service_uri=agentengine://<your_engine_id>— send the same prompt twice in the same session. Observe that every turn creates a new cache with a different fingerprint;cache_nameis never reused.
Expected Behavior:
cache_metadata and usage_metadata should round-trip through Agent Engine sessions the same way they do with InMemorySessionService. The second invocation in the same session should reuse the existing cache.
Observed Behavior:
With VertexAiSessionService, every invocation creates a new cache. The cacheMetadata in events shows a new fingerprint and increasing contents_count each time, with no cache_name reuse.
Environment Details:
- ADK Library Version: 1.25.1
- Desktop OS: macOS
- Python Version: 3.11
Model Information:
- Are you using LiteLLM: Yes/No
- Which model is being used: gemini-2.5-pro
🟡 Optional Information
Regression:
N/A — this has never worked with VertexAiSessionService as far as we can tell (tested 1.19.0 and 1.25.1).
Logs:
With InMemorySessionService (working):
cacheMetadata:
cache_name: "projects/798321343024/locations/us-central1/cachedContents/6261708034305687552"
expire_time: 1772555630.466322
fingerprint: "e8e3e4d5226b764d"
invocations_used: 2
contents_count: 2
created_at: 1772553830.466322
With VertexAiSessionService (broken — new cache every turn):
cacheMetadata:
fingerprint: "c3f575505d7ec95c"
contents_count: 6
Minimal Reproduction Code:
from google.adk.agents import Agent
from google.adk.app import App
from google.adk.context_cache import ContextCacheConfig
root_agent = Agent(
name="test_agent",
model="gemini-2.5-pro",
instruction="You are a helpful assistant.",
)
app = App(
name="test_app",
root_agent=root_agent,
context_cache_config=ContextCacheConfig(
min_tokens=2048,
ttl_seconds=1800,
cache_intervals=10,
),
)
# Works: adk web
# Broken: adk web --session_service_uri=agentengine://<engine_id>How often has this issue occurred?:
- Always (100%)
Activity
llalitkumarrr commentedon Mar 4, 2026
Hello @muzna-naeem ,
Thank you for bringing this to our attention. We were able to reproduce the issue using
google-adk==1.26.0.It appears the failure happens during the if
llm_request.cache_metadatacheck (line no 74) ingemini_context_cache_manager.py. When the ADK websession_service_uriis usedllm_request.cache_metadatais alwaysNonewhich causes the check to fail. However, when using the defaultInmemorysessionservice, it correctly returns aCacheMetadataobject.We are currently investigating why this discrepancy is happening. We appreciate your patience while we look into this further.
Hello @DeanChensj , could you please have a look at this and share your inputs?
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
muzna-naeem commentedon Apr 10, 2026
Hey, any update on this one?
ssingh5bmcd commentedon Apr 16, 2026
Is there any update ?
fix: preserve cache_metadata and usage_metadata in VertexAiSessionSer…
josipTheorem258 commentedon May 25, 2026
Is the intended behavior for ADK ContextCacheConfig to reuse a cache only within the same session, or should it also reuse equivalent caches across sessions when static_instruction + tools docstrings are identical?
Is there any way to create one shared cached content resource for the root agent’s static instruction + tools docstrings, then reuse that same cached content across all Agent Engine sessions when multiple people are talking at the same time?
fufufukakaka commentedon Jun 9, 2026
I really hope things will move forward soon...
DeanChensj commentedon Jun 9, 2026
Hi @muzna-naeem @ssingh5bmcd @fufufukakaka , this issue should be resolved in the latest a few releases. Have you checked? We introduced blob based event storage in vertex ai session service. Could you double check?
adk-bot commentedon Jun 16, 2026
This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
haranrk commentedon Jun 17, 2026
This has been fixed in 9da9dee! As @DeanChensj said, we store the raw event. If the issue persists, please create another issue.