Documentation
¶
Index ¶
- type AgentConfig
- type AgentConstraints
- type CircuitConfig
- type ConfigDeletedEvent
- type ConfigFilter
- type ConfigUpdateRequest
- type ConfigUpdatedEvent
- type EmbeddingStrategy
- type EventPublisher
- type FallbackConfig
- type ModelPreference
- type PostgresRepository
- func (r *PostgresRepository) CreateConfig(ctx context.Context, config *AgentConfig) error
- func (r *PostgresRepository) DeactivateConfig(ctx context.Context, agentID string) error
- func (r *PostgresRepository) DeleteConfig(ctx context.Context, id uuid.UUID) error
- func (r *PostgresRepository) GetConfig(ctx context.Context, agentID string) (*AgentConfig, error)
- func (r *PostgresRepository) GetConfigByID(ctx context.Context, id uuid.UUID) (*AgentConfig, error)
- func (r *PostgresRepository) GetConfigHistory(ctx context.Context, agentID string, limit int) ([]*AgentConfig, error)
- func (r *PostgresRepository) ListConfigs(ctx context.Context, filter ConfigFilter) ([]*AgentConfig, error)
- func (r *PostgresRepository) UpdateConfig(ctx context.Context, agentID string, update *ConfigUpdateRequest) (*AgentConfig, error)
- type QualityConfig
- type RateLimitConfig
- type Repository
- type Service
- func (s *Service) CreateConfig(ctx context.Context, config *AgentConfig) error
- func (s *Service) DeactivateConfig(ctx context.Context, agentID string, deactivatedBy string) error
- func (s *Service) DeleteConfig(ctx context.Context, id uuid.UUID, deletedBy string) error
- func (s *Service) GetCacheStats() map[string]interface{}
- func (s *Service) GetConfig(ctx context.Context, agentID string) (*AgentConfig, error)
- func (s *Service) GetConfigByID(ctx context.Context, id uuid.UUID) (*AgentConfig, error)
- func (s *Service) GetConfigHistory(ctx context.Context, agentID string, limit int) ([]*AgentConfig, error)
- func (s *Service) GetModelsForAgent(ctx context.Context, agentID string, taskType TaskType) (primary []string, fallback []string, err error)
- func (s *Service) ListConfigs(ctx context.Context, filter ConfigFilter) ([]*AgentConfig, error)
- func (s *Service) RefreshCache(ctx context.Context) error
- func (s *Service) UpdateConfig(ctx context.Context, agentID string, update *ConfigUpdateRequest) (*AgentConfig, error)
- func (s *Service) ValidateModels(ctx context.Context, agentID string, models []string) error
- type ServiceOption
- type TaskType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentConfig ¶
type AgentConfig struct {
ID uuid.UUID `json:"id" db:"id"`
AgentID string `json:"agent_id" db:"agent_id" validate:"required,min=3,max=255"`
Version int `json:"version" db:"version"`
EmbeddingStrategy EmbeddingStrategy `json:"embedding_strategy" db:"embedding_strategy" validate:"required,oneof=balanced quality speed cost"`
ModelPreferences []ModelPreference `json:"model_preferences" db:"model_preferences" validate:"required,dive"`
Constraints AgentConstraints `json:"constraints" db:"constraints" validate:"required"`
FallbackBehavior FallbackConfig `json:"fallback_behavior" db:"fallback_behavior"`
Metadata map[string]interface{} `json:"metadata" db:"metadata"`
IsActive bool `json:"is_active" db:"is_active"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
CreatedBy string `json:"created_by" db:"created_by"`
}
AgentConfig represents the complete configuration for an AI agent
func (*AgentConfig) Clone ¶
func (c *AgentConfig) Clone() *AgentConfig
Clone creates a deep copy of the configuration
func (*AgentConfig) FromJSON ¶
func (c *AgentConfig) FromJSON(data []byte) error
FromJSON populates the configuration from JSON
func (*AgentConfig) GetModelsForTask ¶
func (c *AgentConfig) GetModelsForTask(taskType TaskType) (primary []string, fallback []string)
GetModelsForTask returns the models configured for a specific task type
func (*AgentConfig) ToJSON ¶
func (c *AgentConfig) ToJSON() ([]byte, error)
ToJSON converts the configuration to JSON
func (*AgentConfig) Validate ¶
func (c *AgentConfig) Validate() error
Validate validates the agent configuration
type AgentConstraints ¶
type AgentConstraints struct {
MaxCostPerMonthUSD float64 `json:"max_cost_per_month_usd" validate:"min=0"`
MaxLatencyP99Ms int `json:"max_latency_p99_ms" validate:"min=0"`
MinAvailabilitySLA float64 `json:"min_availability_sla" validate:"min=0,max=1"`
RateLimits RateLimitConfig `json:"rate_limits"`
QualityThresholds QualityConfig `json:"quality_thresholds"`
}
AgentConstraints defines operational constraints for an agent
type CircuitConfig ¶
type CircuitConfig struct {
Enabled bool `json:"enabled"`
FailureThreshold int `json:"failure_threshold" validate:"min=1"`
SuccessThreshold int `json:"success_threshold" validate:"min=1"`
TimeoutSeconds int `json:"timeout_seconds" validate:"min=1"`
HalfOpenRequests int `json:"half_open_requests" validate:"min=1"`
}
CircuitConfig defines circuit breaker settings
type ConfigDeletedEvent ¶
type ConfigDeletedEvent struct {
AgentID string `json:"agent_id"`
ConfigID uuid.UUID `json:"config_id"`
DeletedBy string `json:"deleted_by"`
Timestamp time.Time `json:"timestamp"`
}
ConfigDeletedEvent represents a configuration deletion event
type ConfigFilter ¶
type ConfigFilter struct {
AgentID *string `json:"agent_id,omitempty"`
IsActive *bool `json:"is_active,omitempty"`
Strategy *EmbeddingStrategy `json:"strategy,omitempty"`
CreatedBy *string `json:"created_by,omitempty"`
Limit int `json:"limit,omitempty"`
Offset int `json:"offset,omitempty"`
}
ConfigFilter for querying agent configurations
type ConfigUpdateRequest ¶
type ConfigUpdateRequest struct {
EmbeddingStrategy *EmbeddingStrategy `json:"embedding_strategy,omitempty"`
ModelPreferences []ModelPreference `json:"model_preferences,omitempty"`
Constraints *AgentConstraints `json:"constraints,omitempty"`
FallbackBehavior *FallbackConfig `json:"fallback_behavior,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
UpdatedBy string `json:"updated_by" validate:"required"`
}
ConfigUpdateRequest represents a request to update agent configuration
type ConfigUpdatedEvent ¶
type ConfigUpdatedEvent struct {
AgentID string `json:"agent_id"`
ConfigID uuid.UUID `json:"config_id"`
Version int `json:"version"`
UpdatedBy string `json:"updated_by"`
Timestamp time.Time `json:"timestamp"`
}
ConfigUpdatedEvent represents a configuration update event
type EmbeddingStrategy ¶
type EmbeddingStrategy string
EmbeddingStrategy represents the strategy for selecting embedding models
const ( StrategyBalanced EmbeddingStrategy = "balanced" // Balance between cost and quality StrategyQuality EmbeddingStrategy = "quality" // Prioritize quality over cost StrategySpeed EmbeddingStrategy = "speed" // Prioritize speed/latency StrategyCost EmbeddingStrategy = "cost" // Minimize cost )
type EventPublisher ¶
type EventPublisher interface {
PublishConfigUpdated(ctx context.Context, event ConfigUpdatedEvent) error
PublishConfigDeleted(ctx context.Context, event ConfigDeletedEvent) error
}
EventPublisher publishes configuration change events
type FallbackConfig ¶
type FallbackConfig struct {
MaxRetries int `json:"max_retries" validate:"min=0,max=10"`
InitialDelayMs int `json:"initial_delay_ms" validate:"min=0"`
MaxDelayMs int `json:"max_delay_ms" validate:"min=0"`
ExponentialBase float64 `json:"exponential_base" validate:"min=1,max=10"`
QueueOnFailure bool `json:"queue_on_failure"`
QueueTimeoutMs int `json:"queue_timeout_ms" validate:"min=0"`
CircuitBreaker CircuitConfig `json:"circuit_breaker"`
}
FallbackConfig defines behavior when primary models fail
type ModelPreference ¶
type ModelPreference struct {
TaskType TaskType `json:"task_type" validate:"required,oneof=code_analysis general_qa multilingual research"`
PrimaryModels []string `json:"primary_models" validate:"required,min=1"`
FallbackModels []string `json:"fallback_models"`
Weight float64 `json:"weight" validate:"min=0,max=1"` // For weighted selection
}
ModelPreference defines which models an agent prefers for specific tasks
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
PostgresRepository implements Repository using PostgreSQL
func NewPostgresRepository ¶
func NewPostgresRepository(db *sqlx.DB, schema string) *PostgresRepository
NewPostgresRepository creates a new PostgreSQL repository
func (*PostgresRepository) CreateConfig ¶
func (r *PostgresRepository) CreateConfig(ctx context.Context, config *AgentConfig) error
CreateConfig creates a new agent configuration
func (*PostgresRepository) DeactivateConfig ¶
func (r *PostgresRepository) DeactivateConfig(ctx context.Context, agentID string) error
DeactivateConfig deactivates a configuration
func (*PostgresRepository) DeleteConfig ¶
DeleteConfig deletes a configuration (soft delete by deactivating)
func (*PostgresRepository) GetConfig ¶
func (r *PostgresRepository) GetConfig(ctx context.Context, agentID string) (*AgentConfig, error)
GetConfig retrieves the active configuration for an agent
func (*PostgresRepository) GetConfigByID ¶
func (r *PostgresRepository) GetConfigByID(ctx context.Context, id uuid.UUID) (*AgentConfig, error)
GetConfigByID retrieves a specific configuration by ID
func (*PostgresRepository) GetConfigHistory ¶
func (r *PostgresRepository) GetConfigHistory(ctx context.Context, agentID string, limit int) ([]*AgentConfig, error)
GetConfigHistory retrieves configuration history for an agent
func (*PostgresRepository) ListConfigs ¶
func (r *PostgresRepository) ListConfigs(ctx context.Context, filter ConfigFilter) ([]*AgentConfig, error)
ListConfigs lists configurations based on filter
func (*PostgresRepository) UpdateConfig ¶
func (r *PostgresRepository) UpdateConfig(ctx context.Context, agentID string, update *ConfigUpdateRequest) (*AgentConfig, error)
UpdateConfig creates a new version of the configuration
type QualityConfig ¶
type QualityConfig struct {
MinCosineSimilarity float64 `json:"min_cosine_similarity" validate:"min=0,max=1"`
MinEmbeddingMagnitude float64 `json:"min_embedding_magnitude" validate:"min=0"`
AcceptableErrorRate float64 `json:"acceptable_error_rate" validate:"min=0,max=1"`
}
QualityConfig defines quality thresholds
type RateLimitConfig ¶
type RateLimitConfig struct {
RequestsPerMinute int `json:"requests_per_minute" validate:"min=0"`
TokensPerHour int `json:"tokens_per_hour" validate:"min=0"`
ConcurrentRequests int `json:"concurrent_requests" validate:"min=0"`
}
RateLimitConfig defines rate limiting constraints
type Repository ¶
type Repository interface {
// CreateConfig creates a new agent configuration
CreateConfig(ctx context.Context, config *AgentConfig) error
// GetConfig retrieves the active configuration for an agent
GetConfig(ctx context.Context, agentID string) (*AgentConfig, error)
// GetConfigByID retrieves a specific configuration by ID
GetConfigByID(ctx context.Context, id uuid.UUID) (*AgentConfig, error)
// GetConfigHistory retrieves configuration history for an agent
GetConfigHistory(ctx context.Context, agentID string, limit int) ([]*AgentConfig, error)
// UpdateConfig creates a new version of the configuration
UpdateConfig(ctx context.Context, agentID string, update *ConfigUpdateRequest) (*AgentConfig, error)
// ListConfigs lists configurations based on filter
ListConfigs(ctx context.Context, filter ConfigFilter) ([]*AgentConfig, error)
// DeactivateConfig deactivates a configuration
DeactivateConfig(ctx context.Context, agentID string) error
// DeleteConfig deletes a configuration (soft delete)
DeleteConfig(ctx context.Context, id uuid.UUID) error
}
Repository defines the interface for agent configuration storage
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides agent configuration management
func NewService ¶
func NewService(repo Repository, opts ...ServiceOption) *Service
NewService creates a new agent configuration service
func (*Service) CreateConfig ¶
func (s *Service) CreateConfig(ctx context.Context, config *AgentConfig) error
CreateConfig creates a new agent configuration
func (*Service) DeactivateConfig ¶
DeactivateConfig deactivates an agent's configuration
func (*Service) DeleteConfig ¶
DeleteConfig deletes a configuration
func (*Service) GetCacheStats ¶
GetCacheStats returns cache statistics
func (*Service) GetConfigByID ¶
GetConfigByID retrieves a specific configuration by ID
func (*Service) GetConfigHistory ¶
func (s *Service) GetConfigHistory(ctx context.Context, agentID string, limit int) ([]*AgentConfig, error)
GetConfigHistory retrieves configuration history for an agent
func (*Service) GetModelsForAgent ¶
func (s *Service) GetModelsForAgent(ctx context.Context, agentID string, taskType TaskType) (primary []string, fallback []string, err error)
GetModelsForAgent returns the preferred models for an agent's task
func (*Service) ListConfigs ¶
func (s *Service) ListConfigs(ctx context.Context, filter ConfigFilter) ([]*AgentConfig, error)
ListConfigs lists configurations based on filter
func (*Service) RefreshCache ¶
RefreshCache refreshes the configuration cache
func (*Service) UpdateConfig ¶
func (s *Service) UpdateConfig(ctx context.Context, agentID string, update *ConfigUpdateRequest) (*AgentConfig, error)
UpdateConfig updates an agent's configuration
type ServiceOption ¶
type ServiceOption func(*Service)
ServiceOption configures the service
func WithEventPublisher ¶
func WithEventPublisher(publisher EventPublisher) ServiceOption
WithEventPublisher sets the event publisher