Open
Description
Problem
The current ADK implementation has several inefficiencies when handling large context windows (1M-2M tokens) with Gemini models:
- Serialization Bottleneck: State serialization becomes extremely slow with large contexts
- Memory Inefficiency: Duplicate contexts are stored across agents
- Missing Integration: Poor integration with Gemini's context caching mechanism
- Poor Scalability: Memory usage grows linearly with number of agents
Proposed Solution
Implement a reference-based context storage system with the following components:
- A
ContextReferenceStore
class for efficient storage and retrieval of large contexts - An enhanced
LargeContextState
class extending ADK's State - LangGraph integration utilities to support the reference-based approach
Expected Benefits
Initial benchmarks show:
- 600x+ faster serialization
- ~15,900x smaller serialized size
- Up to 49x memory reduction with multiple agents
- Proper integration with Gemini API caching
Implementation Details
Will be provided in the PR, but the approach uses content-based hashing and references to avoid duplicate storage, while maintaining compatibility with existing ADK APIs.