oracular / createState
Function: createState()
function createState(config): EngineState;Defined in: state.ts:37
Builds a fresh engine state from a config. Every intent starts at its prior and no episode is open. The config is validated and a normalized copy is stored inside the state, so a persisted state remembers the weights it was built with; pass your current config to deserialize when loading. config.learning.lift selects the lift formula; omitting it preserves the normalized difference used by existing configs and states.
Parameters
| Parameter | Type | Description |
|---|---|---|
config | EngineConfig | Intents with their priors and signals, plus engine-wide options. Validated strictly: unknown keys, non-finite numbers and out-of-range values throw. |
Returns
A new, JSON-serializable state. config is not mutated.
Throws
TypeError when a value has the wrong type or a key is not recognised.
Throws
RangeError when a number is out of range, for example a prior outside (0, 1), a signal weight of 0, or a weight, priorStrength, learning.gain or learning.priorEpisodes beyond 1e6 (larger values could overflow the arithmetic).
Example
const state = createState({
intents: {
upgrade: {
prior: 0.05,
priorStrength: 10,
halfLife: 7 * 24 * 60 * 60 * 1000,
signals: { 'pricing.viewed': 3, 'limit.hit': 2, 'plan.downgraded': -4 },
outcome: 'upgrade.completed',
},
},
});