Skip to main content

Kernel

Struct Kernel 

Source
pub struct Kernel<O = MultiModalObserver, D = ConstrainedDecisionMaker, E = SandboxedExecutor>
where O: Observer, D: DecisionMaker, E: Executor,
{ /* private fields */ }
Available on crate feature std only.
Expand description

Product-facing kernel. Generic over world I/O and decision maker so callers can inject adapters.

The default Kernel is Send but not Sync: its event hook is FnMut + Send and does not require Sync. Use external synchronization, such as Mutex, before sharing it across threads. The hook signature is kept intentionally compatible with existing adapters.

§Examples

Run a few steps using an in-memory state store:

use omega_cognitive_kernel::{persist::MemoryStateStore, Kernel};

fn main() -> omega_cognitive_kernel::Result<()> {
    let mut kernel = Kernel::open_with_store(Box::new(MemoryStateStore::new()))?;
    let report = kernel.run("stabilize prediction error", 2)?;
    assert_eq!(report.steps, 2);
    assert!(report.final_avg_err.is_finite());
    Ok(())
}

Kernel is not Sync even with the default adapters:

ⓘ
use omega_cognitive_kernel::Kernel;

fn require_sync<T: Sync>() {}
fn main() {
    require_sync::<Kernel>();
}

Implementations§

Source§

impl Kernel<MultiModalObserver, ConstrainedDecisionMaker, SandboxedExecutor>

Source

pub fn new() -> Self

Creates a new value of this type.

Source

pub fn with_state_path(path: impl Into<PathBuf>) -> Self

Creates or updates a value with state path.

Source

pub fn with_bandit_ucb(path: impl Into<PathBuf>) -> BanditKernel

Construct a Kernel with the standard UCB bandit decision maker.

Source

pub fn open(path: Option<&str>) -> Result<Self>

Performs open for this type.

Source

pub fn open_with_store(store: Box<dyn StateStore>) -> Result<Self>

Open a kernel backed by a pluggable StateStore (for example crate::persist::MemoryStateStore).

Source

pub fn from_config_path(config_path: impl AsRef<Path>) -> Result<Self>

Available on crate feature toml only.

Creates a value from config path.

Source

pub fn reset(&mut self) -> Result<()>

Performs reset for this type.

Source§

impl<O, D, E> Kernel<O, D, E>
where O: Observer, D: DecisionMaker, E: Executor,

Source

pub fn with_adapters(observer: O, executor: E, decision: D) -> Self

Creates or updates a value with adapters.

Source

pub fn with_adapters_and_path( observer: O, executor: E, decision: D, path: impl Into<PathBuf>, ) -> Self

Creates or updates a value with adapters and path.

Source

pub fn apply_config(&mut self, cfg: &KernelConfig)

Performs apply config for this type.

Source

pub fn set_event_hook(&mut self, hook: impl FnMut(&AuditEvent) + Send + 'static)

Register an in-process event hook (fires after audit append).

Source

pub fn clear_event_hook(&mut self)

Remove the in-process event hook.

Source

pub fn set_trajectory_max_bytes(&mut self, max_bytes: u64)

Set the maximum trajectory JSONL file size in bytes for future records.

The default is DEFAULT_MAX_TRAJECTORY_BYTES. A zero limit rejects all records; use u64::MAX for an effectively unlimited file. Existing history is never truncated or rotated, and remains available for replay.

Source

pub fn trajectory_max_bytes(&self) -> u64

Get the maximum trajectory JSONL file size in bytes for future records.

Source

pub fn set_audit_max_bytes(&mut self, max_bytes: u64)

Set the maximum audit JSONL file size in bytes for future events.

The default is DEFAULT_MAX_AUDIT_BYTES. A zero limit rejects all records; use u64::MAX for an effectively unlimited file. Existing audit history is never truncated or rotated.

Source

pub fn set_l2_enabled(&mut self, enabled: bool)

Enable or disable L2 interventions while keeping metric evaluation available. Primarily useful for controlled baseline comparisons.

Source

pub fn l1_self_modify_enabled(&self) -> bool

Whether L1 may apply self-modifying patches.

Source

pub fn set_l1_self_modify_enabled(&mut self, enabled: bool)

Enable or disable L1 self-modification without exposing the mutable orchestrator or bypassing the Kernel lifecycle.

Source

pub fn observe_l2_consequence( &mut self, reward_delta: f64, error_delta: f64, risk_delta: f64, )

Feed back the short-term consequence of the latest L2 modulation.

Source

pub fn observe_l2_feedback( &mut self, reward: f64, error: f64, rollback: bool, consequence: f64, kl_policy: [f64; 2], )

Settle the previously applied policy once. The task calls this after external reward and L1 rollback are known, before the next L0 decision. A policy produced by the current L2 step remains pending for next step.

Source

pub fn observe_l1_consequence(&mut self, error_delta: f64) -> bool

Apply L1 RuleEffect rollback independently of L2’s own safety rollback. Returns whether an actual previous effect was restored.

Source

pub fn set_strategy_weight(&mut self, name: &str, weight: f64) -> bool

Operator nudge: set a strategy weight (0.1–10). Returns false if unknown.

Source

pub fn replay_trajectory( &self, tail_n: usize, ) -> Result<TrajectoryReplaySummary>

Performs replay trajectory for this type.

Source

pub fn step(&mut self, goal: &str) -> Result<StepResult>

Run a step with a generated ID. Call Self::step_with_id with a caller-stable ID when a request may be retried after an error or timeout.

Source

pub fn step_with_id(&mut self, step_id: Uuid, goal: &str) -> Result<StepResult>

Run one step under a caller-supplied stable ID.

The ID and goal are written to a durable sidecar journal before any executor call. Reusing the same ID and goal never replays a committed or possibly-dispatched action. A duplicate committed ID returns OmegaError::StepAlreadyCommitted; an incomplete or uncertain attempt returns a distinct error so callers can reconcile external effects. On Unix and Windows, concurrent calls using the same ID and state path are serialized across processes; a competing caller is blocked before executor dispatch.

Source

pub fn run(&mut self, goal: &str, steps: u32) -> Result<RunReport>

Runs run and returns its result.

Source

pub fn status(&self) -> KernelStatus

Performs status for this type.

Source

pub fn metrics_snapshot(&self) -> KernelMetricsSnapshot

Returns a read-only in-memory metrics snapshot for external exporters.

Unlike Self::status, this method does not query case memory through its sampling API and does not inspect checkpoint files. It therefore does not advance the case-memory sampling sequence or perform I/O.

Source

pub fn snapshot(&self) -> KernelSnapshot

Performs snapshot for this type.

Source

pub fn apply_snapshot(&mut self, snap: KernelSnapshot)

Performs apply snapshot for this type.

Source

pub fn snapshot_json(&self) -> Result<String>

Performs snapshot JSON for this type.

Source

pub fn apply_snapshot_json(&mut self, json: &str) -> Result<()>

Performs apply snapshot JSON for this type.

Source

pub fn set_state_store(&mut self, store: Box<dyn StateStore>)

Sets state store.

Source

pub fn has_custom_state_store(&self) -> bool

Returns whether this value has custom state store.

Source

pub fn save(&self) -> Result<()>

Saves the current value.

Source

pub fn load(&mut self) -> Result<()>

Loads the stored value.

Source

pub fn checkpoint(&mut self, label: &str) -> Result<CheckpointMeta>

Performs checkpoint for this type.

Source

pub fn list_checkpoints(&self) -> Result<Vec<CheckpointMeta>>

Performs list checkpoints for this type.

Source

pub fn rollback(&mut self, checkpoint_id: Uuid) -> Result<()>

Performs rollback for this type.

Source

pub fn audit_task(&mut self, task: &str, reward: f64, steps: u32) -> Result<()>

Performs audit task for this type.

Source

pub fn audit_tail(&self, n: usize) -> Result<Vec<AuditRecord>>

Performs audit tail for this type.

Source

pub fn audit_summary(&self) -> Result<AuditSummary>

Performs audit summary for this type.

Source

pub fn inner(&self) -> &OmegaOrchestrator<O, ModelBasedPredictor, D, E>

Performs inner for this type.

Source

pub fn state_path(&self) -> &Path

Performs state path for this type.

Source

pub fn set_state_path(&mut self, path: impl Into<PathBuf>)

Sets state path.

Source

pub fn autosave(&self) -> bool

Performs autosave for this type.

Source

pub fn set_autosave(&mut self, enabled: bool)

Sets autosave.

Source

pub fn auto_checkpoint_on_patch(&self) -> bool

Performs auto checkpoint on patch for this type.

Source

pub fn set_auto_checkpoint_on_patch(&mut self, enabled: bool)

Sets auto checkpoint on patch.

Source

pub fn dump_trajectory(&self) -> bool

Performs dump trajectory for this type.

Source

pub fn set_dump_trajectory(&mut self, enabled: bool)

Sets dump trajectory.

Source

pub fn redact_user_content(&self) -> bool

Performs redact user content for this type.

Source

pub fn set_redact_user_content(&mut self, enabled: bool)

Sets redact user content.

Source

pub fn external_loop_state(&self) -> Option<&ExternalLoopState>

Performs external loop state for this type.

Source

pub fn set_external_loop_state(&mut self, state: Option<ExternalLoopState>)

Sets external loop state.

Source

pub fn audit_max_bytes(&self) -> u64

Performs audit maximum bytes for this type.

Trait Implementations§

Source§

impl<O, D, E> Debug for Kernel<O, D, E>
where O: Observer, D: DecisionMaker, E: Executor,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Kernel<MultiModalObserver, ConstrainedDecisionMaker, SandboxedExecutor>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<O = MultiModalObserver, D = ConstrainedDecisionMaker, E = SandboxedExecutor> !Freeze for Kernel<O, D, E>

§

impl<O = MultiModalObserver, D = ConstrainedDecisionMaker, E = SandboxedExecutor> !RefUnwindSafe for Kernel<O, D, E>

§

impl<O = MultiModalObserver, D = ConstrainedDecisionMaker, E = SandboxedExecutor> !Sync for Kernel<O, D, E>

§

impl<O = MultiModalObserver, D = ConstrainedDecisionMaker, E = SandboxedExecutor> !UnwindSafe for Kernel<O, D, E>

§

impl<O, D, E> Forget for Kernel<O, D, E>

§

impl<O, D, E> Move for Kernel<O, D, E>

§

impl<O, D, E> Send for Kernel<O, D, E>
where E: Send, D: Send, O: Send, RawVecInner: Send, NonZero<i32>: Send, Utc: Send, Cell<u32>: Send, NodeRef<Owned, String, Strategy, LeafOrInternal>: Send, BoxRaw<(String, Strategy)>: Send, NodeRef<Owned, String, f64, LeafOrInternal>: Send, BoxRaw<(String, f64)>: Send, NodeRef<Owned, String, String, LeafOrInternal>: Send, BoxRaw<(String, String)>: Send, BoxRaw<dyn FnMut(&AuditEvent) + Send>: Send, BoxRaw<dyn StateStore>: Send,

§

impl<O, D, E> Unpin for Kernel<O, D, E>
where E: Unpin, D: Unpin, O: Unpin, *const u8 is !null: Unpin, NonZero<i32>: Unpin, Utc: Unpin, *const LeafNode<String, Strategy> is !null: Unpin, Box<(String, Strategy)>: Unpin, *const LeafNode<String, f64> is !null: Unpin, Box<(String, f64)>: Unpin, *const LeafNode<String, String> is !null: Unpin, Box<(String, String)>: Unpin, Box<dyn FnMut(&AuditEvent) + Send>: Unpin, Box<dyn StateStore>: Unpin,

§

impl<O, D, E> UnsafeUnpin for Kernel<O, D, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more