pub struct PolicyKernel { /* private fields */ }Expand description
Persistent routing policy store.
Wraps a PolicyKernelState with load/save operations tied to a
file path. Changes are saved eagerly on every mutation.
Implementations§
Source§impl PolicyKernel
impl PolicyKernel
Sourcepub fn agent_path(agent_id: &str) -> Option<PathBuf>
pub fn agent_path(agent_id: &str) -> Option<PathBuf>
Resolve the default policy kernel path for a given agent.
Returns ~/.clawft/agents/<agent_id>/policy_kernel.json.
Sourcepub fn global_path() -> Option<PathBuf>
pub fn global_path() -> Option<PathBuf>
Resolve the default global policy kernel path.
Returns ~/.clawft/memory/policy_kernel.json.
Sourcepub fn load(path: &Path) -> Result<Self, PolicyKernelError>
pub fn load(path: &Path) -> Result<Self, PolicyKernelError>
Load the policy kernel from disk, or create a new empty one.
If the file does not exist, returns an empty kernel that will create the file on the first save.
Sourcepub fn save(&self) -> Result<(), PolicyKernelError>
pub fn save(&self) -> Result<(), PolicyKernelError>
Save the current state to disk.
Sourcepub fn add_policy(
&mut self,
id: String,
pattern: String,
embedding: Vec<f32>,
tier: u8,
) -> Result<(), PolicyKernelError>
pub fn add_policy( &mut self, id: String, pattern: String, embedding: Vec<f32>, tier: u8, ) -> Result<(), PolicyKernelError>
Add a routing policy and persist to disk.
Sourcepub fn record_cost(
&mut self,
model: &str,
tokens: u64,
cost: f32,
latency_ms: u64,
) -> Result<(), PolicyKernelError>
pub fn record_cost( &mut self, model: &str, tokens: u64, cost: f32, latency_ms: u64, ) -> Result<(), PolicyKernelError>
Record a cost observation and persist to disk.
Sourcepub fn policies(&self) -> &[PolicyEntry]
pub fn policies(&self) -> &[PolicyEntry]
Return the policy entries (read-only).
Sourcepub fn cost_records(&self) -> &[PersistedCostRecord]
pub fn cost_records(&self) -> &[PersistedCostRecord]
Return the cost records (read-only).
Sourcepub fn policy_count(&self) -> usize
pub fn policy_count(&self) -> usize
Return the number of policy entries.
Sourcepub fn state(&self) -> &PolicyKernelState
pub fn state(&self) -> &PolicyKernelState
Return the full state (for export).
Sourcepub fn set_state(
&mut self,
state: PolicyKernelState,
) -> Result<(), PolicyKernelError>
pub fn set_state( &mut self, state: PolicyKernelState, ) -> Result<(), PolicyKernelError>
Replace the full state (for import). Saves immediately.
Sourcepub fn clear(&mut self) -> Result<(), PolicyKernelError>
pub fn clear(&mut self) -> Result<(), PolicyKernelError>
Clear all policies and cost records. Saves immediately.
Auto Trait Implementations§
impl Freeze for PolicyKernel
impl RefUnwindSafe for PolicyKernel
impl Send for PolicyKernel
impl Sync for PolicyKernel
impl Unpin for PolicyKernel
impl UnsafeUnpin for PolicyKernel
impl UnwindSafe for PolicyKernel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more