Documentation
¶
Index ¶
- type AgentCRD
- type AgentCRDStatus
- type AgentCondition
- type AgentInstance
- type AgentOperator
- func (o *AgentOperator) ExportCRD(namespace, name string) ([]byte, error)
- func (o *AgentOperator) GetAgent(namespace, name string) *AgentCRD
- func (o *AgentOperator) GetInstances(namespace, name string) []*AgentInstance
- func (o *AgentOperator) GetMetrics() *OperatorMetrics
- func (o *AgentOperator) ImportCRD(data []byte) error
- func (o *AgentOperator) ListAgents() []*AgentCRD
- func (o *AgentOperator) RegisterAgent(agent *AgentCRD) error
- func (o *AgentOperator) SetHealthCheckCallback(fn func(agent *AgentCRD) (bool, error))
- func (o *AgentOperator) SetInstanceProvider(p InstanceProvider)
- func (o *AgentOperator) SetReconcileCallback(fn func(agent *AgentCRD) error)
- func (o *AgentOperator) SetScaleCallback(fn func(agent *AgentCRD, replicas int32) error)
- func (o *AgentOperator) Start(ctx context.Context) error
- func (o *AgentOperator) Stop()
- func (o *AgentOperator) UnregisterAgent(namespace, name string) error
- func (o *AgentOperator) UpdateInstanceMetrics(instanceID string, metrics InstanceMetrics)
- type AgentPhase
- type AgentSpec
- type HealthCheckSpec
- type InMemoryInstanceProvider
- func (p *InMemoryInstanceProvider) CreateInstance(_ context.Context, agent *AgentCRD) (*AgentInstance, error)
- func (p *InMemoryInstanceProvider) DeleteInstance(_ context.Context, instanceID string) error
- func (p *InMemoryInstanceProvider) GetInstanceStatus(_ context.Context, instanceID string) (InstanceStatus, error)
- func (p *InMemoryInstanceProvider) ListInstances(_ context.Context, namespace, name string) ([]*AgentInstance, error)
- type InstanceMetrics
- type InstanceProvider
- type InstanceStatus
- type MetricValue
- type ModelSpec
- type ObjectMeta
- type OperatorConfig
- type OperatorMetrics
- type ResourceQuantity
- type ResourceSpec
- type ScalingBehavior
- type ScalingPolicy
- type ScalingRules
- type ScalingSpec
- type TargetMetric
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AgentCRD ¶
type AgentCRD struct {
APIVersion string `json:"apiVersion"`
Kind string `json:"kind"`
Metadata ObjectMeta `json:"metadata"`
Spec AgentSpec `json:"spec"`
Status AgentCRDStatus `json:"status,omitempty"`
}
AgentCRD代表一个代理的自定义资源定义.
type AgentCRDStatus ¶
type AgentCRDStatus struct {
Phase AgentPhase `json:"phase"`
Replicas int32 `json:"replicas"`
ReadyReplicas int32 `json:"readyReplicas"`
AvailableReplicas int32 `json:"availableReplicas"`
Conditions []AgentCondition `json:"conditions,omitempty"`
LastScaleTime *time.Time `json:"lastScaleTime,omitempty"`
CurrentMetrics []MetricValue `json:"currentMetrics,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}
AgentCRD status 代表被观察到的特工状态.
type AgentCondition ¶
type AgentCondition struct {
Type string `json:"type"`
Status string `json:"status"` // True, False, Unknown
LastTransitionTime time.Time `json:"lastTransitionTime"`
Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}
代理条件代表着代理的条件.
type AgentInstance ¶
type AgentInstance struct {
ID string `json:"id"`
AgentName string `json:"agentName"`
Namespace string `json:"namespace"`
Status InstanceStatus `json:"status"`
StartTime time.Time `json:"startTime"`
LastHealthy time.Time `json:"lastHealthy"`
Metrics InstanceMetrics `json:"metrics"`
Labels map[string]string `json:"labels,omitempty"`
}
代理Instance代表运行的代理实例.
type AgentOperator ¶
type AgentOperator struct {
// contains filtered or unexported fields
}
AgentOperator为特工执行Kubernetes操作器.
func NewAgentOperator ¶
func NewAgentOperator(config OperatorConfig, logger *zap.Logger) *AgentOperator
新代理运营商创建了新的代理运营商.
func (*AgentOperator) ExportCRD ¶
func (o *AgentOperator) ExportCRD(namespace, name string) ([]byte, error)
ExportCRD向JSON出口一名代理CRD.
func (*AgentOperator) GetAgent ¶
func (o *AgentOperator) GetAgent(namespace, name string) *AgentCRD
Get Agent 以命名空间和名称检索代理 。
func (*AgentOperator) GetInstances ¶
func (o *AgentOperator) GetInstances(namespace, name string) []*AgentInstance
GetInstances 为代理返回所有实例 。
func (*AgentOperator) GetMetrics ¶
func (o *AgentOperator) GetMetrics() *OperatorMetrics
GetMetrics 返回操作员的度量衡 。
func (*AgentOperator) ImportCRD ¶
func (o *AgentOperator) ImportCRD(data []byte) error
进口CRD从JSON进口一个代理CRD.
func (*AgentOperator) ListAgents ¶
func (o *AgentOperator) ListAgents() []*AgentCRD
ListAgents列出所有注册代理.
func (*AgentOperator) RegisterAgent ¶
func (o *AgentOperator) RegisterAgent(agent *AgentCRD) error
注册代理注册代理CRD.
func (*AgentOperator) SetHealthCheckCallback ¶
func (o *AgentOperator) SetHealthCheckCallback(fn func(agent *AgentCRD) (bool, error))
SetHealthCheckCallback 设置健康检查回调.
func (*AgentOperator) SetInstanceProvider ¶ added in v1.0.0
func (o *AgentOperator) SetInstanceProvider(p InstanceProvider)
SetInstanceProvider replaces the default in-memory instance provider.
func (*AgentOperator) SetReconcileCallback ¶
func (o *AgentOperator) SetReconcileCallback(fn func(agent *AgentCRD) error)
设置调和 Callback 设置调和调回调 。
func (*AgentOperator) SetScaleCallback ¶
func (o *AgentOperator) SetScaleCallback(fn func(agent *AgentCRD, replicas int32) error)
设置缩放Callback 设置缩放回调 。
func (*AgentOperator) UnregisterAgent ¶
func (o *AgentOperator) UnregisterAgent(namespace, name string) error
未注册代理删除代理CRD.
func (*AgentOperator) UpdateInstanceMetrics ¶
func (o *AgentOperator) UpdateInstanceMetrics(instanceID string, metrics InstanceMetrics)
更新InstanceMetrics为实例更新了度量衡.
type AgentPhase ¶
type AgentPhase string
代理阶段代表代理阶段.
const ( AgentPhasePending AgentPhase = "Pending" AgentPhaseRunning AgentPhase = "Running" AgentPhaseScaling AgentPhase = "Scaling" AgentPhaseDegraded AgentPhase = "Degraded" AgentPhaseFailed AgentPhase = "Failed" AgentPhaseTerminating AgentPhase = "Terminating" )
type AgentSpec ¶
type AgentSpec struct {
AgentType string `json:"agentType"`
Replicas int32 `json:"replicas"`
Model ModelSpec `json:"model"`
Resources ResourceSpec `json:"resources"`
Scaling ScalingSpec `json:"scaling,omitempty"`
HealthCheck HealthCheckSpec `json:"healthCheck,omitempty"`
Environment map[string]string `json:"environment,omitempty"`
ConfigMapRef string `json:"configMapRef,omitempty"`
SecretRef string `json:"secretRef,omitempty"`
}
AgentSpec定义了Agent的理想状态.
type HealthCheckSpec ¶
type HealthCheckSpec struct {
Enabled bool `json:"enabled"`
Interval time.Duration `json:"interval"`
Timeout time.Duration `json:"timeout"`
FailureThreshold int32 `json:"failureThreshold"`
SuccessThreshold int32 `json:"successThreshold"`
InitialDelaySeconds int32 `json:"initialDelaySeconds,omitempty"`
}
健康检查Spec定义健康检查配置.
type InMemoryInstanceProvider ¶ added in v1.0.0
type InMemoryInstanceProvider struct {
// contains filtered or unexported fields
}
InMemoryInstanceProvider manages agent instances in memory. It implements InstanceProvider for testing and local development.
func NewInMemoryInstanceProvider ¶ added in v1.0.0
func NewInMemoryInstanceProvider(logger *zap.Logger) *InMemoryInstanceProvider
NewInMemoryInstanceProvider creates a new in-memory instance provider.
func (*InMemoryInstanceProvider) CreateInstance ¶ added in v1.0.0
func (p *InMemoryInstanceProvider) CreateInstance(_ context.Context, agent *AgentCRD) (*AgentInstance, error)
CreateInstance creates a new agent instance in memory.
func (*InMemoryInstanceProvider) DeleteInstance ¶ added in v1.0.0
func (p *InMemoryInstanceProvider) DeleteInstance(_ context.Context, instanceID string) error
DeleteInstance removes an instance by ID.
func (*InMemoryInstanceProvider) GetInstanceStatus ¶ added in v1.0.0
func (p *InMemoryInstanceProvider) GetInstanceStatus(_ context.Context, instanceID string) (InstanceStatus, error)
GetInstanceStatus returns the status of an instance.
func (*InMemoryInstanceProvider) ListInstances ¶ added in v1.0.0
func (p *InMemoryInstanceProvider) ListInstances(_ context.Context, namespace, name string) ([]*AgentInstance, error)
ListInstances returns all instances for a given namespace and agent name.
type InstanceMetrics ¶
type InstanceMetrics struct {
RequestsTotal int64 `json:"requestsTotal"`
RequestsPerSecond float64 `json:"requestsPerSecond"`
AverageLatency time.Duration `json:"averageLatency"`
ErrorRate float64 `json:"errorRate"`
CPUUsage float64 `json:"cpuUsage"`
MemoryUsage float64 `json:"memoryUsage"`
TokensUsed int64 `json:"tokensUsed"`
}
实例计量包含一个代理实例的衡量标准。
type InstanceProvider ¶ added in v1.0.0
type InstanceProvider interface {
CreateInstance(ctx context.Context, agent *AgentCRD) (*AgentInstance, error)
DeleteInstance(ctx context.Context, instanceID string) error
GetInstanceStatus(ctx context.Context, instanceID string) (InstanceStatus, error)
ListInstances(ctx context.Context, namespace, name string) ([]*AgentInstance, error)
}
InstanceProvider abstracts how agent instances are created/destroyed. Default implementation is in-memory. K8s implementation would use client-go.
type InstanceStatus ¶
type InstanceStatus string
案件状况代表代理人案件的状况。
const ( InstanceStatusPending InstanceStatus = "Pending" InstanceStatusRunning InstanceStatus = "Running" InstanceStatusHealthy InstanceStatus = "Healthy" InstanceStatusUnhealthy InstanceStatus = "Unhealthy" InstanceStatusFailed InstanceStatus = "Failed" )
type MetricValue ¶
type MetricValue struct {
Name string `json:"name"`
CurrentValue int64 `json:"currentValue"`
TargetValue int64 `json:"targetValue"`
}
MetricValue 代表当前计量值。
type ModelSpec ¶
type ModelSpec struct {
Provider string `json:"provider"`
Model string `json:"model"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
}
ModelSpec定义了LLM模型配置.
type ObjectMeta ¶
type ObjectMeta struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Labels map[string]string `json:"labels,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
UID string `json:"uid,omitempty"`
ResourceVersion string `json:"resourceVersion,omitempty"`
Generation int64 `json:"generation,omitempty"`
CreationTime time.Time `json:"creationTimestamp,omitempty"`
}
ObjectMeta包含标准Kubernetes对象元数据.
type OperatorConfig ¶
type OperatorConfig struct {
Namespace string `json:"namespace"`
ReconcileInterval time.Duration `json:"reconcileInterval"`
MetricsPort int `json:"metricsPort"`
HealthProbePort int `json:"healthProbePort"`
LeaderElection bool `json:"leaderElection"`
LeaderElectionID string `json:"leaderElectionId"`
WatchNamespaces []string `json:"watchNamespaces,omitempty"`
EnableWebhooks bool `json:"enableWebhooks"`
CertDir string `json:"certDir,omitempty"`
MaxConcurrentReconciles int `json:"maxConcurrentReconciles"`
}
操作员Config 配置 Kubernetes 操作员 。
type OperatorMetrics ¶
type OperatorMetrics struct {
ReconcileTotal atomic.Int64 `json:"reconcileTotal"`
ReconcileErrors atomic.Int64 `json:"reconcileErrors"`
ScaleUpEvents atomic.Int64 `json:"scaleUpEvents"`
ScaleDownEvents atomic.Int64 `json:"scaleDownEvents"`
SelfHealingEvents atomic.Int64 `json:"selfHealingEvents"`
AverageReconcileTime atomic.Int64 `json:"averageReconcileTime"` // nanoseconds
}
运算仪包含运算器级的度量衡.
type ResourceQuantity ¶
type ResourceQuantity struct {
CPU string `json:"cpu,omitempty"`
Memory string `json:"memory,omitempty"`
GPU string `json:"gpu,omitempty"`
}
资源数量定义了CPU和内存数量.
type ResourceSpec ¶
type ResourceSpec struct {
Requests ResourceQuantity `json:"requests,omitempty"`
Limits ResourceQuantity `json:"limits,omitempty"`
}
资源Spec定义了所需资源.
type ScalingBehavior ¶
type ScalingBehavior struct {
ScaleUp *ScalingRules `json:"scaleUp,omitempty"`
ScaleDown *ScalingRules `json:"scaleDown,omitempty"`
}
缩放行为定义自定义缩放行为 。
type ScalingPolicy ¶
type ScalingPolicy struct {
Type string `json:"type"` // Pods, Percent
Value int32 `json:"value"`
PeriodSeconds int32 `json:"periodSeconds"`
}
缩放政策界定了单一缩放政策.
type ScalingRules ¶
type ScalingRules struct {
StabilizationWindowSeconds int32 `json:"stabilizationWindowSeconds,omitempty"`
Policies []ScalingPolicy `json:"policies,omitempty"`
}
缩放规则定义了缩放规则.
type ScalingSpec ¶
type ScalingSpec struct {
Enabled bool `json:"enabled"`
MinReplicas int32 `json:"minReplicas"`
MaxReplicas int32 `json:"maxReplicas"`
TargetMetrics []TargetMetric `json:"targetMetrics,omitempty"`
ScaleDownDelay time.Duration `json:"scaleDownDelay,omitempty"`
ScaleUpDelay time.Duration `json:"scaleUpDelay,omitempty"`
CooldownPeriod time.Duration `json:"cooldownPeriod,omitempty"`
CustomBehavior *ScalingBehavior `json:"behavior,omitempty"`
}
缩放Spec 定义自动缩放配置 。