pub struct CompactionState { /* private fields */ }Expand description
压缩运行时状态 — 跟踪熔断器与防重复触发。
由 Session 持有,在 Agent loop 期间维护。
§Examples
use katu_agent::compaction::CompactionState;
let mut state = CompactionState::new();
assert!(!state.is_circuit_broken(3));
state.record_failure();
state.record_failure();
state.record_failure();
assert!(state.is_circuit_broken(3));
state.record_success();
assert!(!state.is_circuit_broken(3));Implementations§
Source§impl CompactionState
impl CompactionState
Sourcepub fn record_success(&mut self)
pub fn record_success(&mut self)
记录一次压缩成功 — 重置熔断器。
Sourcepub fn record_failure(&mut self)
pub fn record_failure(&mut self)
记录一次压缩失败 — 递增熔断器计数。
Sourcepub fn is_circuit_broken(&self, max_failures: u32) -> bool
pub fn is_circuit_broken(&self, max_failures: u32) -> bool
熔断器是否已触发。
max_failures == 0 表示不限制。
Sourcepub fn mark_compacted(&mut self, step: u32, tokens_after: Option<u64>)
pub fn mark_compacted(&mut self, step: u32, tokens_after: Option<u64>)
标记当前步已执行压缩。
Sourcepub fn already_compacted_at(&self, step: u32) -> bool
pub fn already_compacted_at(&self, step: u32) -> bool
检查指定步是否已执行过压缩(防重复)。
Sourcepub fn consecutive_failures(&self) -> u32
pub fn consecutive_failures(&self) -> u32
连续失败次数。
Sourcepub fn last_compact_tokens(&self) -> Option<u64>
pub fn last_compact_tokens(&self) -> Option<u64>
上次压缩后的 token 数。
Trait Implementations§
Source§impl Clone for CompactionState
impl Clone for CompactionState
Source§fn clone(&self) -> CompactionState
fn clone(&self) -> CompactionState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for CompactionState
impl Debug for CompactionState
Auto Trait Implementations§
impl Freeze for CompactionState
impl RefUnwindSafe for CompactionState
impl Send for CompactionState
impl Sync for CompactionState
impl Unpin for CompactionState
impl UnsafeUnpin for CompactionState
impl UnwindSafe for CompactionState
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
Mutably borrows from an owned value. Read more