Skip to main content

DetectionConfig

Struct DetectionConfig 

Source
pub struct DetectionConfig {
    pub loop_threshold: usize,
    pub stop_threshold: usize,
    pub enable_loop_detection: bool,
    pub max_history: usize,
    pub convergence_threshold: f32,
    pub convergence_count: usize,
    pub enable_convergence_detection: bool,
    pub on_converge: ConvergenceAction,
}
Expand description

Configuration for the DetectionManager.

Groups all tunables for loop detection and convergence detection in a single struct so consumers can construct a DetectionManager with one call to DetectionManager::new_with_config.

The Default implementation provides sensible production values: loop threshold 3, stop threshold 10, convergence threshold 0.95, and convergence count 3.

§Sections

The configuration is divided into two groups:

§Example

let config = DetectionConfig {
    loop_threshold: 5,          // allow more repetition before flagging
    convergence_threshold: 0.9, // looser similarity threshold
    ..DetectionConfig::default()
};
let dm = DetectionManager::new_with_config(config);

§See Also

Fields§

§loop_threshold: usize

Consecutive similar operations before declaring a loop. Default: 3.

Number of times the same (tool, primary_param, result_hash) signature must recur within the window before DetectedPattern::LoopDetected is reported. Lower it to catch loops sooner at the cost of more false positives.

§stop_threshold: usize

Repetitions triggering forced stop (0 = disabled). Default: 10.

When a single operation’s repetition count reaches this value, the detector sets LoopStatus::should_stop so the caller halts the agent. Setting it to 0 disables forced stops entirely while still issuing warnings. The count is window-relative, not cumulative: max_history eviction can reset it, so a stuck operation interleaved with enough distinct traffic may never reach the threshold — raise max_history if slow loops must be caught.

§enable_loop_detection: bool

Whether loop detection is enabled. Default: true.

Master switch for the tool-loop subsystem. When false, DetectionManager::record_operation short-circuits and returns DetectedPattern::NoPattern without consulting the loop detector.

§max_history: usize

Max operations kept in loop detector history. Default: 100.

Size of the sliding window the loop detector retains. A larger window catches slower loops that span many interleaved operations; a smaller one uses less memory and forgets stale patterns faster.

§convergence_threshold: f32

Jaccard similarity threshold for convergence (0.0–1.0). Default: 0.95.

Minimum Jaccard similarity a response must share with its predecessor to extend the convergence streak. Lower it to catch paraphrased repetition; raise it toward 1.0 to demand near-verbatim matches.

§convergence_count: usize

Consecutive similar responses for convergence. Default: 3.

Streak length of consecutive similar responses required before DetectedPattern::ConvergenceDetected is reported. Maps to the convergence detector’s window size.

§enable_convergence_detection: bool

Whether convergence detection is enabled. Default: true.

Master switch for the response-convergence subsystem. When false, DetectionManager::record_response short-circuits and returns DetectedPattern::NoPattern without consulting the convergence detector.

§on_converge: ConvergenceAction

Action on convergence. Default: ConvergenceAction::Warn — text similarity is a heuristic with irreducible false positives, so its default punishment is not execution. Set ConvergenceAction::Stop to restore stop-on-converge.

The ConvergenceAction forwarded to callers once convergence is detected — stop, warn, switch phase, ask the user, or compact the history. Drives how the agent responds to a detected stall.

Implementations§

Source§

impl DetectionConfig

Source

pub fn to_convergence_config(&self) -> ConvergenceConfig

Convert convergence settings into a ConvergenceConfig.

§Field Mapping
DetectionConfig fieldConvergenceConfig field
enable_convergence_detectionenabled
convergence_countwindow_size
convergence_thresholdsimilarity_threshold
on_convergeon_converge
Source

pub fn to_loop_detector_config(&self) -> LoopDetectorConfig

Convert the loop-related settings into a LoopDetectorConfig.

§Field Mapping
DetectionConfig fieldLoopDetectorConfig field
max_historywindow_size
loop_thresholdrepetition_threshold
stop_thresholdstop_threshold

Trait Implementations§

Source§

impl Clone for DetectionConfig

Source§

fn clone(&self) -> DetectionConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DetectionConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for DetectionConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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