Add to working memory (auto-trims by relevance if over capacity)
(&self, item: MemoryItem)
| 227 | |
| 228 | /// Add to working memory (auto-trims by relevance if over capacity) |
| 229 | pub async fn add_to_working(&self, item: MemoryItem) -> anyhow::Result<()> { |
| 230 | let mut working = self.working.write().await; |
| 231 | working.push(item); |
| 232 | if working.len() > self.max_working { |
| 233 | let now = Utc::now(); |
| 234 | working.sort_by(|a, b| { |
| 235 | self.score(b, now) |
| 236 | .partial_cmp(&self.score(a, now)) |
| 237 | .unwrap_or(std::cmp::Ordering::Equal) |
| 238 | }); |
| 239 | working.truncate(self.max_working); |
| 240 | } |
| 241 | Ok(()) |
| 242 | } |
| 243 | |
| 244 | /// Get working memory |
| 245 | pub async fn get_working(&self) -> Vec<MemoryItem> { |