pub struct Kernel<O = MultiModalObserver, D = ConstrainedDecisionMaker, E = SandboxedExecutor>{ /* private fields */ }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>
impl Kernel<MultiModalObserver, ConstrainedDecisionMaker, SandboxedExecutor>
Sourcepub fn with_state_path(path: impl Into<PathBuf>) -> Self
pub fn with_state_path(path: impl Into<PathBuf>) -> Self
Creates or updates a value with state path.
Sourcepub fn with_bandit_ucb(path: impl Into<PathBuf>) -> BanditKernel
pub fn with_bandit_ucb(path: impl Into<PathBuf>) -> BanditKernel
Construct a Kernel with the standard UCB bandit decision maker.
Sourcepub fn open_with_store(store: Box<dyn StateStore>) -> Result<Self>
pub fn open_with_store(store: Box<dyn StateStore>) -> Result<Self>
Open a kernel backed by a pluggable StateStore (for example crate::persist::MemoryStateStore).
Sourcepub fn from_config_path(config_path: impl AsRef<Path>) -> Result<Self>
Available on crate feature toml only.
pub fn from_config_path(config_path: impl AsRef<Path>) -> Result<Self>
toml only.Creates a value from config path.
Source§impl<O, D, E> Kernel<O, D, E>
impl<O, D, E> Kernel<O, D, E>
Sourcepub fn with_adapters(observer: O, executor: E, decision: D) -> Self
pub fn with_adapters(observer: O, executor: E, decision: D) -> Self
Creates or updates a value with adapters.
Sourcepub fn with_adapters_and_path(
observer: O,
executor: E,
decision: D,
path: impl Into<PathBuf>,
) -> Self
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.
Sourcepub fn apply_config(&mut self, cfg: &KernelConfig)
pub fn apply_config(&mut self, cfg: &KernelConfig)
Performs apply config for this type.
Sourcepub fn set_event_hook(&mut self, hook: impl FnMut(&AuditEvent) + Send + 'static)
pub fn set_event_hook(&mut self, hook: impl FnMut(&AuditEvent) + Send + 'static)
Register an in-process event hook (fires after audit append).
Sourcepub fn clear_event_hook(&mut self)
pub fn clear_event_hook(&mut self)
Remove the in-process event hook.
Sourcepub fn set_trajectory_max_bytes(&mut self, max_bytes: u64)
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.
Sourcepub fn trajectory_max_bytes(&self) -> u64
pub fn trajectory_max_bytes(&self) -> u64
Get the maximum trajectory JSONL file size in bytes for future records.
Sourcepub fn set_audit_max_bytes(&mut self, max_bytes: u64)
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.
Sourcepub fn set_l2_enabled(&mut self, enabled: bool)
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.
Sourcepub fn l1_self_modify_enabled(&self) -> bool
pub fn l1_self_modify_enabled(&self) -> bool
Whether L1 may apply self-modifying patches.
Sourcepub fn set_l1_self_modify_enabled(&mut self, enabled: bool)
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.
Sourcepub fn observe_l2_consequence(
&mut self,
reward_delta: f64,
error_delta: f64,
risk_delta: f64,
)
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.
Sourcepub fn observe_l2_feedback(
&mut self,
reward: f64,
error: f64,
rollback: bool,
consequence: f64,
kl_policy: [f64; 2],
)
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.
Sourcepub fn observe_l1_consequence(&mut self, error_delta: f64) -> bool
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.
Sourcepub fn set_strategy_weight(&mut self, name: &str, weight: f64) -> bool
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.
Sourcepub fn replay_trajectory(
&self,
tail_n: usize,
) -> Result<TrajectoryReplaySummary>
pub fn replay_trajectory( &self, tail_n: usize, ) -> Result<TrajectoryReplaySummary>
Performs replay trajectory for this type.
Sourcepub fn step(&mut self, goal: &str) -> Result<StepResult>
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.
Sourcepub fn step_with_id(&mut self, step_id: Uuid, goal: &str) -> Result<StepResult>
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.
Sourcepub fn run(&mut self, goal: &str, steps: u32) -> Result<RunReport>
pub fn run(&mut self, goal: &str, steps: u32) -> Result<RunReport>
Runs run and returns its result.
Sourcepub fn status(&self) -> KernelStatus
pub fn status(&self) -> KernelStatus
Performs status for this type.
Sourcepub fn metrics_snapshot(&self) -> KernelMetricsSnapshot
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.
Sourcepub fn snapshot(&self) -> KernelSnapshot
pub fn snapshot(&self) -> KernelSnapshot
Performs snapshot for this type.
Sourcepub fn apply_snapshot(&mut self, snap: KernelSnapshot)
pub fn apply_snapshot(&mut self, snap: KernelSnapshot)
Performs apply snapshot for this type.
Sourcepub fn snapshot_json(&self) -> Result<String>
pub fn snapshot_json(&self) -> Result<String>
Performs snapshot JSON for this type.
Sourcepub fn apply_snapshot_json(&mut self, json: &str) -> Result<()>
pub fn apply_snapshot_json(&mut self, json: &str) -> Result<()>
Performs apply snapshot JSON for this type.
Sourcepub fn set_state_store(&mut self, store: Box<dyn StateStore>)
pub fn set_state_store(&mut self, store: Box<dyn StateStore>)
Sets state store.
Sourcepub fn has_custom_state_store(&self) -> bool
pub fn has_custom_state_store(&self) -> bool
Returns whether this value has custom state store.
Sourcepub fn checkpoint(&mut self, label: &str) -> Result<CheckpointMeta>
pub fn checkpoint(&mut self, label: &str) -> Result<CheckpointMeta>
Performs checkpoint for this type.
Sourcepub fn list_checkpoints(&self) -> Result<Vec<CheckpointMeta>>
pub fn list_checkpoints(&self) -> Result<Vec<CheckpointMeta>>
Performs list checkpoints for this type.
Sourcepub fn audit_task(&mut self, task: &str, reward: f64, steps: u32) -> Result<()>
pub fn audit_task(&mut self, task: &str, reward: f64, steps: u32) -> Result<()>
Performs audit task for this type.
Sourcepub fn audit_tail(&self, n: usize) -> Result<Vec<AuditRecord>>
pub fn audit_tail(&self, n: usize) -> Result<Vec<AuditRecord>>
Performs audit tail for this type.
Sourcepub fn audit_summary(&self) -> Result<AuditSummary>
pub fn audit_summary(&self) -> Result<AuditSummary>
Performs audit summary for this type.
Sourcepub fn inner(&self) -> &OmegaOrchestrator<O, ModelBasedPredictor, D, E>
pub fn inner(&self) -> &OmegaOrchestrator<O, ModelBasedPredictor, D, E>
Performs inner for this type.
Sourcepub fn state_path(&self) -> &Path
pub fn state_path(&self) -> &Path
Performs state path for this type.
Sourcepub fn set_state_path(&mut self, path: impl Into<PathBuf>)
pub fn set_state_path(&mut self, path: impl Into<PathBuf>)
Sets state path.
Sourcepub fn set_autosave(&mut self, enabled: bool)
pub fn set_autosave(&mut self, enabled: bool)
Sets autosave.
Sourcepub fn auto_checkpoint_on_patch(&self) -> bool
pub fn auto_checkpoint_on_patch(&self) -> bool
Performs auto checkpoint on patch for this type.
Sourcepub fn set_auto_checkpoint_on_patch(&mut self, enabled: bool)
pub fn set_auto_checkpoint_on_patch(&mut self, enabled: bool)
Sets auto checkpoint on patch.
Sourcepub fn dump_trajectory(&self) -> bool
pub fn dump_trajectory(&self) -> bool
Performs dump trajectory for this type.
Sourcepub fn set_dump_trajectory(&mut self, enabled: bool)
pub fn set_dump_trajectory(&mut self, enabled: bool)
Sets dump trajectory.
Sourcepub fn redact_user_content(&self) -> bool
pub fn redact_user_content(&self) -> bool
Performs redact user content for this type.
Sourcepub fn set_redact_user_content(&mut self, enabled: bool)
pub fn set_redact_user_content(&mut self, enabled: bool)
Sets redact user content.
Sourcepub fn external_loop_state(&self) -> Option<&ExternalLoopState>
pub fn external_loop_state(&self) -> Option<&ExternalLoopState>
Performs external loop state for this type.
Sourcepub fn set_external_loop_state(&mut self, state: Option<ExternalLoopState>)
pub fn set_external_loop_state(&mut self, state: Option<ExternalLoopState>)
Sets external loop state.
Sourcepub fn audit_max_bytes(&self) -> u64
pub fn audit_max_bytes(&self) -> u64
Performs audit maximum bytes for this type.