pub struct ThinkLoop {
pub goal: String,
pub max_iterations: usize,
pub convergence_threshold: f64,
pub k_proportional: f64,
pub k_integral: f64,
pub stall_patience: usize,
pub promotion_threshold: f64,
pub hot: HotStore,
pub cold: ColdStore,
}Expand description
The closed-loop controller that drives the agent’s reasoning process.
Build via ThinkLoop::new or ThinkLoop::builder, then call
.run(&mut oracle).await to obtain a ThinkResult.
§Examples
use lmm_agent::cognition::r#loop::ThinkLoop;
use lmm_agent::cognition::search::SearchOracle;
#[tokio::main]
async fn main() {
let mut oracle = SearchOracle::new(3);
let mut lp = ThinkLoop::new("Rust memory safety", 5, 0.3, 1.0, 0.05);
let result = lp.run(&mut oracle).await;
println!("converged={} steps={} error={:.3}", result.converged, result.steps, result.final_error);
}Fields§
§goal: StringNatural-language goal (setpoint).
max_iterations: usizeMaximum number of feedback iterations.
convergence_threshold: f64Jaccard-error threshold below which convergence is declared.
k_proportional: f64Proportional gain constant (Kp).
k_integral: f64Integral gain constant (Ki) - stored for documentation; applied in CognitionSignal.
stall_patience: usizeConsecutive reward-declining steps before stall detection triggers.
promotion_threshold: f64Reward score threshold for promoting hot entries to cold store.
hot: HotStoreShort-term memory for the current run.
cold: ColdStoreLong-term memory archive.
Implementations§
Source§impl ThinkLoop
impl ThinkLoop
Sourcepub fn new(
goal: impl Into<String>,
max_iterations: usize,
convergence_threshold: f64,
k_proportional: f64,
k_integral: f64,
) -> Self
pub fn new( goal: impl Into<String>, max_iterations: usize, convergence_threshold: f64, k_proportional: f64, k_integral: f64, ) -> Self
Constructs a ThinkLoop with the given parameters.
§Arguments
goal- natural-language goal / setpoint.max_iterations- iteration cap (≥ 1).convergence_threshold- Jaccard error threshold ∈ [0, 1].k_proportional- proportional gain Kp.k_integral- integral gain Ki.
Sourcepub fn builder(goal: impl Into<String>) -> ThinkLoopBuilder
pub fn builder(goal: impl Into<String>) -> ThinkLoopBuilder
Returns a builder for ergonomic construction.
Sourcepub fn stall_patience(self, n: usize) -> Self
pub fn stall_patience(self, n: usize) -> Self
Sets the stall patience.
Sourcepub fn promotion_threshold(self, t: f64) -> Self
pub fn promotion_threshold(self, t: f64) -> Self
Sets the hot→cold promotion reward threshold.
Sourcepub async fn run(&mut self, oracle: &mut SearchOracle) -> ThinkResult
pub async fn run(&mut self, oracle: &mut SearchOracle) -> ThinkResult
Runs the closed-loop think cycle and returns a ThinkResult.
§Examples
#[tokio::main]
async fn main() {
use lmm_agent::cognition::r#loop::ThinkLoop;
use lmm_agent::cognition::search::SearchOracle;
let mut oracle = SearchOracle::new(5);
let mut lp = ThinkLoop::new("Rust memory model", 10, 0.25, 1.0, 0.05);
let r = lp.run(&mut oracle).await;
assert!(r.steps > 0);
}