decision

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPUThreshold

type CPUThreshold struct {
	MaxPercent float64
}

CPUThreshold defines CPU threshold.

type Context

type Context struct {
	// Request data
	Task       string
	Complexity int
	Resources  *ResourceEstimate // optional, from client

	// Current system state
	CurrentState *monitor.SystemState

	// Model prediction (may be nil if no data)
	Prediction *ResourceImpact

	// Configuration
	Thresholds   *ThresholdsConfig
	SafetyBuffer float64 // for conservative strategy (e.g., 0.10 = 10%)

	// Pending tasks (for queue_aware strategy)
	PendingTasks []PendingTask
}

Context contains all information needed for making a decision.

func NewContext

func NewContext(task string, complexity int) *Context

NewContext creates a new decision context.

func (*Context) WithCurrentState

func (c *Context) WithCurrentState(state *monitor.SystemState) *Context

WithCurrentState sets the current system state.

func (*Context) WithPendingTasks

func (c *Context) WithPendingTasks(tasks []PendingTask) *Context

WithPendingTasks sets the pending tasks for queue_aware strategy.

func (*Context) WithPrediction

func (c *Context) WithPrediction(prediction *ResourceImpact) *Context

WithPrediction sets the model prediction.

func (*Context) WithResources

func (c *Context) WithResources(resources *ResourceEstimate) *Context

WithResources sets the client's resource estimate.

func (*Context) WithSafetyBuffer

func (c *Context) WithSafetyBuffer(buffer float64) *Context

WithSafetyBuffer sets the safety buffer for conservative strategy.

func (*Context) WithThresholds

func (c *Context) WithThresholds(thresholds *ThresholdsConfig) *Context

WithThresholds sets the threshold configuration.

type FutureState

type FutureState struct {
	CPUPercent    float64 `json:"cpu_percent"`
	MemoryPercent float64 `json:"memory_percent"`
	GPUPercent    float64 `json:"gpu_percent,omitempty"`
	VRAMPercent   float64 `json:"vram_percent,omitempty"`
}

FutureState represents predicted system state after task execution.

type GPUThreshold

type GPUThreshold struct {
	MaxPercent float64
}

GPUThreshold defines GPU threshold.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager coordinates decision making.

func NewManager

func NewManager(
	strategy Strategy,
	model PredictionModel,
	aggregator *monitor.Aggregator,
	cfg ManagerConfig,
) *Manager

NewManager creates a new decision manager.

func (*Manager) AddPendingTask

func (m *Manager) AddPendingTask(task PendingTask)

AddPendingTask adds a task to the pending list.

func (*Manager) Decide

func (m *Manager) Decide(task string, complexity int, resources *ResourceEstimate) *Result

Decide makes a decision about whether a task can run.

func (*Manager) Model

func (m *Manager) Model() PredictionModel

Model returns the current model.

func (*Manager) PendingCount

func (m *Manager) PendingCount() int

PendingCount returns the number of pending tasks.

func (*Manager) RemovePendingTask

func (m *Manager) RemovePendingTask(taskID string)

RemovePendingTask removes a task from the pending list.

func (*Manager) Strategy

func (m *Manager) Strategy() Strategy

Strategy returns the current strategy.

func (*Manager) UpdateThresholds

func (m *Manager) UpdateThresholds(thresholds *ThresholdsConfig)

UpdateThresholds updates the threshold configuration.

type ManagerConfig

type ManagerConfig struct {
	Thresholds   *ThresholdsConfig
	SafetyBuffer float64
}

ManagerConfig holds manager configuration.

type MemoryThreshold

type MemoryThreshold struct {
	MaxPercent float64
}

MemoryThreshold defines memory threshold.

type PendingTask

type PendingTask struct {
	Task       string
	Complexity int
	StartedAt  time.Time
	Predicted  *ResourceImpact
}

PendingTask represents a task awaiting observation.

type PredictionModel

type PredictionModel interface {
	Name() string
	Predict(task string, complexity int) *ResourceImpact
	Observe(task string, complexity int, impact *ResourceImpact)
	Confidence(task string) float64
}

PredictionModel defines the interface for resource impact prediction. This is duplicated here to avoid import cycles. The actual implementation is in decision/model package.

type Reason

type Reason string

Reason represents a reason for rejecting a task.

const (
	ReasonCPUOverload      Reason = "cpu_overload"
	ReasonMemoryOverload   Reason = "memory_overload"
	ReasonGPUOverload      Reason = "gpu_overload"
	ReasonVRAMOverload     Reason = "vram_overload"
	ReasonStorageLow       Reason = "storage_low"
	ReasonInsufficientData Reason = "insufficient_data"
)

type ResourceEstimate

type ResourceEstimate struct {
	CPU    int `json:"cpu,omitempty"`
	GPU    int `json:"gpu,omitempty"`
	Memory int `json:"memory,omitempty"`
}

ResourceEstimate represents client's estimate of resource requirements.

type ResourceImpact

type ResourceImpact struct {
	CPUDelta    float64 `json:"cpu_delta"`
	MemoryDelta float64 `json:"memory_delta"`
	GPUDelta    float64 `json:"gpu_delta,omitempty"`
	VRAMDelta   float64 `json:"vram_delta,omitempty"`
}

ResourceImpact represents the predicted or observed impact on resources.

type Result

type Result struct {
	// Main result
	Allowed bool     `json:"allowed"`
	Reasons []Reason `json:"reasons,omitempty"`

	// Predicted state after task execution
	PredictedState *FutureState `json:"predicted,omitempty"`

	// Confidence in the decision (0-1)
	Confidence float64 `json:"confidence"`

	// Metadata
	Strategy string `json:"strategy"`
	Model    string `json:"model"`
}

Result contains the decision outcome.

type StorageThreshold

type StorageThreshold struct {
	MinFreeGB float64
}

StorageThreshold defines storage threshold.

type Strategy

type Strategy interface {
	Name() string
	Decide(ctx *Context) *Result
}

Strategy defines the interface for decision-making strategies. This is duplicated here to avoid import cycles. The actual implementation is in decision/strategy package.

type ThresholdsConfig

type ThresholdsConfig struct {
	CPU     CPUThreshold
	Memory  MemoryThreshold
	GPU     GPUThreshold
	VRAM    VRAMThreshold
	Storage StorageThreshold
}

ThresholdsConfig holds threshold configuration for decisions.

type VRAMThreshold

type VRAMThreshold struct {
	MaxPercent float64
}

VRAMThreshold defines VRAM threshold.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL