Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions go/api/v1alpha2/agent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,19 @@ type DeclarativeAgentSpec struct {
// +optional
// due to a bug in adk (https://github.com/google/adk-python/issues/3921), this field is ignored for now.
ExecuteCodeBlocks *bool `json:"executeCodeBlocks,omitempty"`

// Context configures context management for this agent.
// This includes event compaction (compression) and context caching.
// +optional
Context *ContextConfig `json:"context,omitempty"`

// Memory configures the memory for the agent.
// +optional
Memory *MemoryConfig `json:"memory,omitempty"`

// Resumability configures the resumability for the agent.
// +optional
Resumability *ResumabilityConfig `json:"resumability,omitempty"`
}

type DeclarativeDeploymentSpec struct {
Expand All @@ -127,6 +140,133 @@ type DeclarativeDeploymentSpec struct {
SharedDeploymentSpec `json:",inline"`
}

// ResumabilityConfig configures the resumability for the agent.
type ResumabilityConfig struct {
// IsResumable enables agent resumability.
// +optional
IsResumable bool `json:"isResumable,omitempty"`
}

// MemoryType represents the memory type
// +kubebuilder:validation:Enum=InMemory;VertexAI;McpServer
type MemoryType string

const (
MemoryTypeInMemory MemoryType = "InMemory"
MemoryTypeVertexAI MemoryType = "VertexAI"
MemoryTypeMcpServer MemoryType = "McpServer"
)

// MemoryConfig configures the memory for the agent.
// +kubebuilder:validation:XValidation:rule="!has(self.inMemory) || self.type == 'InMemory'",message="inMemory configuration is only allowed when type is InMemory"
// +kubebuilder:validation:XValidation:rule="!has(self.vertexAi) || self.type == 'VertexAI'",message="vertexAi configuration is only allowed when type is VertexAI"
// +kubebuilder:validation:XValidation:rule="!has(self.mcpServer) || self.type == 'McpServer'",message="mcpServer configuration is only allowed when type is McpServer"
type MemoryConfig struct {
// +kubebuilder:default=InMemory
Type MemoryType `json:"type"`

// +optional
InMemory *InMemoryConfig `json:"inMemory,omitempty"`
// +optional
VertexAI *VertexAIMemoryConfig `json:"vertexAi,omitempty"`
// +optional
McpServer *McpMemoryConfig `json:"mcpServer,omitempty"`
}

type InMemoryConfig struct {
}

type VertexAIMemoryConfig struct {
// +optional
ProjectID string `json:"projectID,omitempty"`
// +optional
Location string `json:"location,omitempty"`
}

type McpMemoryConfig struct {
// Name is the name of the MCP server resource.
Name string `json:"name"`
// Kind is the kind of the MCP server resource.
// +optional
// +kubebuilder:default=MCPServer
Kind string `json:"kind,omitempty"`
// ApiGroup is the API group of the MCP server resource.
// +optional
// +kubebuilder:default=kagent.dev
ApiGroup string `json:"apiGroup,omitempty"`
}

// ContextConfig configures context management for an agent.
// Context management includes event compaction (compression/summarization) and context caching.
type ContextConfig struct {
// Compaction configures event history compaction.
// When enabled, older events in the conversation are compacted (compressed/summarized)
// to reduce context size while preserving key information.
// +optional
Compaction *ContextCompressionConfig `json:"compaction,omitempty"`
// Cache configures context caching.
// When enabled, prefix context is cached at the provider level to reduce
// redundant processing of repeated context.
// +optional
Cache *ContextCacheConfig `json:"cache,omitempty"`
}

// ContextCompressionConfig configures event history compaction/compression.
// +kubebuilder:validation:XValidation:rule="has(self.compactionInterval) && has(self.overlapSize)",message="compactionInterval and overlapSize are required"
type ContextCompressionConfig struct {
// The number of *new* user-initiated invocations that, once fully represented in the session's events, will trigger a compaction.
// +kubebuilder:validation:Minimum=1
CompactionInterval int `json:"compactionInterval"`
// The number of preceding invocations to include from the end of the last compacted range. This creates an overlap between consecutive compacted summaries, maintaining context.
// +kubebuilder:validation:Minimum=0
OverlapSize int `json:"overlapSize"`
// Summarizer configures an LLM-based summarizer for event compaction.
// If not specified, compacted events are simply truncated without summarization.
// +optional
Summarizer *ContextSummarizerConfig `json:"summarizer,omitempty"`
// Post-invocation token threshold trigger. If set, ADK will attempt a post-invocation compaction when the most recently
// observed prompt token count meets or exceeds this threshold.
// +optional
TokenThreshold *int `json:"tokenThreshold,omitempty"`
// EventRetentionSize is the number of most recent events to always retain.
// +optional
EventRetentionSize *int `json:"eventRetentionSize,omitempty"`
}

// ContextSummarizerConfig configures the LLM-based event summarizer.
type ContextSummarizerConfig struct {
// ModelConfig is the name of a ModelConfig resource to use for summarization.
// Must be in the same namespace as the Agent.
// If not specified, uses the agent's own model.
// +optional
ModelConfig string `json:"modelConfig,omitempty"`
// PromptTemplate is a custom prompt template for the summarizer.
// +optional
PromptTemplate string `json:"promptTemplate,omitempty"`
}

// ContextCacheConfig configures prefix context caching at the LLM provider level.
type ContextCacheConfig struct {
// CacheIntervals specifies how often (in number of events) to update the cache.
// Default: 10
// +optional
// +kubebuilder:default=10
// +kubebuilder:validation:Minimum=1
CacheIntervals *int `json:"cacheIntervals,omitempty"`
// TTLSeconds specifies the time-to-live for cached context in seconds.
// Default: 1800 (30 minutes)
// +optional
// +kubebuilder:default=1800
// +kubebuilder:validation:Minimum=0
TTLSeconds *int `json:"ttlSeconds,omitempty"`
// MinTokens is the minimum number of tokens before caching is activated.
// Default: 0
// +optional
// +kubebuilder:default=0
// +kubebuilder:validation:Minimum=0
MinTokens *int `json:"minTokens,omitempty"`
}

type BYOAgentSpec struct {
// Trust relationship to the agent.
// +optional
Expand Down
Loading