pub struct PreCompactHandler {
orchestrator: CaptureOrchestrator,
llm: Option<Arc<dyn LlmProvider>>,
use_llm_analysis: bool,
}Expand description
Handler for the PreCompact hook event.
Analyzes context being compacted and auto-captures valuable memories.
Integrates with DeduplicationService to check for duplicates before capture.
§Deduplication
When a deduplication service is configured, each candidate is checked against:
- Exact match: SHA256 hash comparison
- Semantic similarity: Embedding cosine similarity (if embeddings available)
- Recent capture: LRU cache with TTL
Duplicates are skipped and reported in the hook output.
§LLM Analysis Mode
When an LLM provider is configured and use_llm_analysis is enabled, content
that doesn’t match keyword-based detection patterns will be analyzed by the
LLM for classification. This provides more accurate namespace assignment at
the cost of increased latency.
Configure via environment variable: SUBCOG_AUTO_CAPTURE_USE_LLM=true
Fields§
§orchestrator: CaptureOrchestratorCapture orchestrator for coordinating captures with deduplication.
llm: Option<Arc<dyn LlmProvider>>Optional LLM provider for content classification.
use_llm_analysis: boolWhether to use LLM for classifying ambiguous content.
Implementations§
Source§impl PreCompactHandler
impl PreCompactHandler
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new PreCompact handler.
The use_llm_analysis setting is loaded from the environment variable
SUBCOG_AUTO_CAPTURE_USE_LLM (default: false).
Sourcepub fn with_capture(self, capture: CaptureService) -> Self
pub fn with_capture(self, capture: CaptureService) -> Self
Sets the capture service.
Sourcepub fn with_deduplication(self, dedup: Arc<dyn Deduplicator>) -> Self
pub fn with_deduplication(self, dedup: Arc<dyn Deduplicator>) -> Self
Sets the deduplication service.
When set, candidates are checked for duplicates before capture. Duplicates are skipped and reported in the hook output.
Sourcepub fn with_llm(self, llm: Arc<dyn LlmProvider>) -> Self
pub fn with_llm(self, llm: Arc<dyn LlmProvider>) -> Self
Sets the LLM provider for content classification.
When set (and SUBCOG_AUTO_CAPTURE_USE_LLM=true), content that doesn’t
match keyword-based detection will be analyzed by the LLM.
Sourcepub const fn with_llm_analysis(self, enabled: bool) -> Self
pub const fn with_llm_analysis(self, enabled: bool) -> Self
Enables or disables LLM analysis mode.
This overrides the SUBCOG_AUTO_CAPTURE_USE_LLM environment variable.
Sourcefn analyze_content(&self, input: &PreCompactInput) -> Vec<CaptureCandidate>
fn analyze_content(&self, input: &PreCompactInput) -> Vec<CaptureCandidate>
Analyzes content and extracts capture candidates.
Sourcefn classify_with_llm(&self, section: &str) -> Option<CaptureCandidate>
fn classify_with_llm(&self, section: &str) -> Option<CaptureCandidate>
Uses LLM to classify content that didn’t match keyword detection.
Returns Some(CaptureCandidate) if the LLM suggests capturing,
None if LLM is unavailable or suggests not capturing.
Sourcefn extract_from_text(&self, text: &str) -> Vec<CaptureCandidate>
fn extract_from_text(&self, text: &str) -> Vec<CaptureCandidate>
Extracts potential memories from text.
Uses keyword-based detection first, then optionally falls back to LLM
classification if use_llm_analysis is enabled.
Trait Implementations§
Source§impl Default for PreCompactHandler
impl Default for PreCompactHandler
Source§impl HookHandler for PreCompactHandler
impl HookHandler for PreCompactHandler
Auto Trait Implementations§
impl Freeze for PreCompactHandler
impl !RefUnwindSafe for PreCompactHandler
impl Send for PreCompactHandler
impl Sync for PreCompactHandler
impl Unpin for PreCompactHandler
impl !UnwindSafe for PreCompactHandler
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].