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
impl Compactor
Sourcepub fn new(config: CompactConfig, client: Arc<dyn LLMClient>) -> Self
pub fn new(config: CompactConfig, client: Arc<dyn LLMClient>) -> Self
Creates a compactor over client with config.
Sourcepub fn with_client(client: Arc<dyn LLMClient>) -> Self
pub fn with_client(client: Arc<dyn LLMClient>) -> Self
Creates a compactor over client with default CompactConfig.
Sourcepub async fn record_turn(&self, user: String, assistant: String) -> CompactEvent
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.
Sourcepub async fn audit_if_due(&self) -> Vec<CompactEvent>
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).
Sourcepub fn build_context(
&self,
base: &str,
recent_window: usize,
) -> Vec<(String, String)>
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.
Sourcepub fn export(&self) -> CompactionState
pub fn export(&self) -> CompactionState
Exports the full compaction state for persistence (DB snapshot row).
Sourcepub fn hydrate(
config: CompactConfig,
client: Arc<dyn LLMClient>,
state: CompactionState,
) -> Self
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.
Sourcepub fn state_snapshot(&self) -> CompactionSnapshot
pub fn state_snapshot(&self) -> CompactionSnapshot
Counted view of the current state for tests and admin surfaces.