Skip to main content

Compactor

Struct Compactor 

Source
pub struct Compactor { /* private fields */ }
Expand description

History compaction service running small frequent micro-calls over one shared client. See the module docs for the pipeline.

Implementations§

Source§

impl Compactor

Source

pub fn new(config: CompactConfig, client: Arc<dyn LLMClient>) -> Self

Creates a compactor over client with config.

Source

pub fn with_client(client: Arc<dyn LLMClient>) -> Self

Creates a compactor over client with default CompactConfig.

Source

pub async fn record_turn(&self, user: String, assistant: String) -> CompactEvent

Records one user/assistant turn and scores THE PAIR with a single micro-call.

A transport failure yields CompactEvent::Skipped with reason score-call; an unparseable reply yields score-parse. Either way the turn is stored unscored and the caller never sees an error.

Source

pub async fn audit_if_due(&self) -> Vec<CompactEvent>

Runs an audit pass when due: enough new turns arrived (CompactConfig::trigger_turns) or live history exceeds CompactConfig::history_turns.

One batched call re-scores every unscored or weak turn; then S-tier (5) turns are hoisted VERBATIM into the deduplicated critical list, the rolling memory is rebuilt from mid-tier facts in one more call (skipped when there is nothing new to summarize), and low-value turns outside the grace window are evicted. Returns a single-element vector: CompactEvent::Audited on success or CompactEvent::Skipped (not-due, audit-call, audit-parse).

Source

pub fn build_context( &self, base: &str, recent_window: usize, ) -> Vec<(String, String)>

Builds message pairs ready for generate_with_history callers: [base, critical, memory, recent turns], in that order. The critical and memory slots appear only when non-empty; recent_window bounds how many newest turns ride along.

Source

pub fn export(&self) -> CompactionState

Exports the full compaction state for persistence (DB snapshot row).

Source

pub fn hydrate( config: CompactConfig, client: Arc<dyn LLMClient>, state: CompactionState, ) -> Self

Rebuilds a compactor from previously Compactor::exported state, restoring entries, critical facts, memory and audit position.

Source

pub fn state_snapshot(&self) -> CompactionSnapshot

Counted view of the current state for tests and admin surfaces.

Auto Trait Implementations§

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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, <T as TryFrom<U>>::Error>

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