Documentation
¶
Overview ¶
Package control is a generic adaptive-control primitive: it reads signals from named sources, aggregates them into a vector, and drives a mode FSM whose transitions are gated by threshold expressions.
"AI director" is one application — Left 4 Dead / Vermintide / Helldivers monitor party stress, transition between calm/build/peak modes, and schedule horde events. The same mechanism shows up in:
- k8s autoscaler — monitor load metrics, transition cluster size.
- Alert manager — monitor incident signal, transition severity.
- Dynamic pricing — read demand, transition price tier.
- Trading regime detection — read volatility, transition risk mode.
Domain-free by design — the mode names and signal sources are supplied by the caller.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator samples a named set of sources and returns the combined vector. Safe for concurrent use.
func NewAggregator ¶
func NewAggregator(sources map[string]Source) *Aggregator
NewAggregator constructs an Aggregator from a name → Source map.
func (*Aggregator) AddSource ¶
func (a *Aggregator) AddSource(name string, s Source)
AddSource registers (or replaces) a source by name.
type Comparison ¶
type Comparison uint8
Comparison enumerates the ordering operators a Threshold can apply.
const ( // CmpGT — value > threshold. CmpGT Comparison = iota // CmpGE — value >= threshold. CmpGE // CmpLT — value < threshold. CmpLT // CmpLE — value <= threshold. CmpLE // CmpEQ — value == threshold (use sparingly with floats). CmpEQ )
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller drives a Mode FSM from the aggregator's signal vector. Safe for concurrent use.
func NewController ¶
func NewController(agg *Aggregator, modes []Mode, initial string) *Controller
NewController constructs a Controller. `initial` must be one of the Mode names.
func (*Controller) SetClock ¶
func (c *Controller) SetClock(f func() time.Time)
SetClock overrides the wall clock; used in tests.
type Mode ¶
type Mode struct {
Name string
OnEnter func(ctx context.Context)
OnTick func(ctx context.Context, vec map[string]Signal)
Transitions []ModeTransition
// MinDwell, if > 0, prevents leaving this mode until at least
// MinDwell has elapsed since entering. Used to suppress thrashing
// when signals oscillate near a threshold.
MinDwell time.Duration
}
Mode is one control-loop mode. OnEnter fires when the controller transitions to this mode; OnTick fires every Tick while this mode is active. Transitions are evaluated after OnTick; the first one whose Conditions all hold wins.
type ModeTransition ¶
ModeTransition is one outgoing edge from a Mode. All Conditions must hold for the transition to fire (AND).
type Signal ¶
type Signal float64
Signal is a scalar reading from a single source at a point in time.
type SourceFunc ¶
SourceFunc adapts a function to the Source interface.
type Threshold ¶
type Threshold struct {
Signal string
Cmp Comparison
Value Signal
}
Threshold is a single comparison on a named signal.