# Useful but Little-Known Features of ADK 2.0
🌍 Sending the same system prompt and tool definitions to the LLM on every call wastes both money and time. What if the SDK could cache that for you?
ADK 2.0's ContextCacheConfig caches repeated context data sent to the LLM, reducing both API costs and response latency. Available with Gemini 2.0+, Python v1.15.0+, and Java v0.1.0+.
📌 Title: Context Cache (ContextCacheConfig)
🔗 URL:
🧩 Overview
ContextCacheConfig reduces token consumption by caching context sent to the LLM — system prompts, tool definitions, fixed portions of conversation history, and more. It has three key parameters: min_tokens sets the minimum token threshold for caching to activate (default 0), ttl_seconds controls cache lifetime (default 1800 seconds / 30 minutes), and cache_intervals limits maximum cache reuse count (default 10). Configure it on the App object and caching is applied automatically.
🛠 How to use it
Create a ContextCacheConfig and set it on the App.
```python
from import App
from google.adk.context import ContextCacheConfig
cache_config = ContextCacheConfig(
min_tokens=1000, # Cache only when context >= 1000 tokens
ttl_seconds=3600, # Keep cache for 1 hour
cache_intervals=20, # Reuse up to 20 times
)
app = App(
agent=my_agent,
context_cache_config=cache_config,
)
```
Setting min_tokens appropriately ensures that small contexts are sent normally while large contexts benefit from caching.
🏗 Building it into production
・Agents with large system prompts or many tool definitions benefit the most from caching
・Tune ttl_seconds to match your workload pattern (short conversations → shorter TTL, long ones → longer TTL)
・Adjust cache_intervals based on request frequency to balance freshness and cost savings
・Monitor cost reduction metrics and continuously optimize parameters
💡 Use cases
💰 Cut API costs for agents with large, stable system prompts
⚡ Reduce response latency by skipping repeated tool definition transmission
🔁 Optimize token consumption for high-frequency chatbot interactions
📋 Efficiently handle fixed context (rules, guidelines, policies) that rarely changes
⚠️ Watch out
This feature requires Gemini 2.0 or later. Context changes won't take effect while a cache is active, so set a shorter ttl_seconds if you frequently update system prompts. When cache_intervals is exceeded, a new cache is created, which can cause cost optimization effects to fluctuate.
✨ Context caching delivers significant cost and performance improvements, especially in scenarios with large, frequently-accessed context. It's a quick win for production deployments.
#
ADK# #
AIAgent#