-
Notifications
You must be signed in to change notification settings - Fork 352
Open
Description
Summary
When using kagent with models that have limited context windows (e.g., gpt-4o-mini with 128k tokens), agents with many MCP tools can exceed the context limit, causing "Session terminated" errors.
Currently, kagent does not expose ADK's context management features through the Agent CRD.
Problem
With an agent configured with ~40+ MCP tools, the context quickly exceeds limits:
- Each tool definition adds tokens to the context
- Conversation history accumulates
- No way to truncate, summarize, or manage context programmatically
Error observed:
context_length_exceeded: This model's maximum context length is 128000 tokens.
However, your messages resulted in 155XXX tokens.
Proposed Solution
Expose ADK's context management capabilities through the Agent CRD:
Option 1: Context Compression (Compaction)
ADK has Context Compression that summarizes older events:
apiVersion: kagent.dev/v1alpha2
kind: Agent
spec:
declarative:
contextCompression:
enabled: true
compactionInterval: 5 # Compress every 5 events
overlapSize: 1
summarizer:
type: llm # Use LlmEventSummarizer
model: gpt-4o-miniOption 2: Context Caching
ADK has Context Caching for optimizing repeated requests:
spec:
declarative:
contextCache:
enabled: true
minTokens: 1000
ttlSeconds: 3600
cacheIntervals: 10Option 3: Context Window Compression Config
From the ADK API, there's ContextWindowCompressionConfig:
spec:
declarative:
contextWindowCompression:
enabled: true
maxLength: 100000 # Max context length before compressionAlternatives Considered
- Reduce tools: Works but limits agent capabilities
- Use larger context models: More expensive (gpt-4o vs gpt-4o-mini)
- Memory/RAG: Currently not supported in ADK (v0.6 release notes confirm this)
Additional Context
- ADK already implements these features, they just need to be exposed in the CRD
- This is critical for production deployments with complex agents
- ADK documentation: https://google.github.io/adk-docs/context/
Environment
- kagent version: v0.7.6
- Kubernetes: OpenShift 4.17
- Model: gpt-4o-mini (128k context)
- Tools: 16 MCP tools (reduced from 42 to mitigate issue)
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Backlog