fix(agent): use config max_tool_iterations, add memory relevance filtering, rebalance search weights

Three fixes for conversation quality issues:

1. loop_.rs and channels now read max_tool_iterations from AgentConfig
   instead of using a hardcoded constant of 10, making it configurable.

2. Memory recall now filters entries below a configurable
   min_relevance_score threshold (default 0.4), preventing unrelated
   memories from bleeding into conversation context.

3. Default hybrid search weights rebalanced from 70/30 vector/keyword
   to 40/60, reducing cross-topic semantic bleed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Edvard 2026-02-17 20:09:06 -05:00 committed by Chummy
parent 21c5f58363
commit 8a1e7cc7ef
6 changed files with 90 additions and 24 deletions

View file

@ -10,18 +10,23 @@ pub trait MemoryLoader: Send + Sync {
pub struct DefaultMemoryLoader {
limit: usize,
min_relevance_score: f64,
}
impl Default for DefaultMemoryLoader {
fn default() -> Self {
Self { limit: 5 }
Self {
limit: 5,
min_relevance_score: 0.4,
}
}
}
impl DefaultMemoryLoader {
pub fn new(limit: usize) -> Self {
pub fn new(limit: usize, min_relevance_score: f64) -> Self {
Self {
limit: limit.max(1),
min_relevance_score,
}
}
}
@ -40,8 +45,19 @@ impl MemoryLoader for DefaultMemoryLoader {
let mut context = String::from("[Memory context]\n");
for entry in entries {
if let Some(score) = entry.score {
if score < self.min_relevance_score {
continue;
}
}
let _ = writeln!(context, "- {}: {}", entry.key, entry.content);
}
// If all entries were below threshold, return empty
if context == "[Memory context]\n" {
return Ok(String::new());
}
context.push('\n');
Ok(context)
}