av_loopdetect/lib.rs
1//! Semantic loop detection & circuit breaking (brief Module A).
2//!
3//! Recursive agents stuck in loops rarely repeat verbatim — they paraphrase.
4//! Off the hot path, a worker embeds each reasoning step and computes the
5//! semantic delta Δ = 1 − cosine(eᵢ, eᵢ₊₁) — tightened, when vector history
6//! is available, to `min(Δ, 1 − nearest-prior-step similarity)` so loops
7//! that alternate between two paraphrases still trip. The breaker trips when Δ ≈ 0
8//! (below `delta_epsilon`) for `window` consecutive steps while the session
9//! consumed ≥ `min_tokens` — exactly the brief's rule (Δ≈0 across 3 steps
10//! while consuming N+ tokens).
11//!
12//! The default [`HashEmbedder`] is a deterministic char-n-gram
13//! feature-hashing embedder: zero model downloads, air-gap-safe, catches
14//! verbatim and paraphrase-dense loops (SLA-tested). MiniLM-class ONNX models
15//! plug in behind the `onnx` feature via the same [`Embedder`] trait
16//! (tract-onnx, pure Rust — no PyTorch/Python runtime, per the brief).
17
18pub mod breaker;
19pub mod embed;
20pub mod vector_sink;
21
22pub use breaker::{BreakerAction, BreakerConfig, BreakerState, BreakerVerdict, SessionLoopState};
23pub use embed::{cosine, Embedder, HashEmbedder};
24pub use vector_sink::{NoopVectorSink, VectorSearchFuture, VectorSink, VectorSinkFuture};
25
26#[cfg(feature = "qdrant")]
27pub use vector_sink::QdrantVectorSink;
28
29#[cfg(feature = "onnx")]
30pub mod onnx_embed;
31#[cfg(feature = "onnx")]
32pub use onnx_embed::OnnxEmbedder;