MCPcopy Index your code
hub / github.com/AI45Lab/Code / add_to_working

Method add_to_working

core/src/memory.rs:229–242  ·  view source on GitHub ↗

Add to working memory (auto-trims by relevance if over capacity)

(&self, item: MemoryItem)

Source from the content-addressed store, hash-verified

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> {

Calls 5

nowFunction · 0.85
writeMethod · 0.80
scoreMethod · 0.80
lenMethod · 0.45
truncateMethod · 0.45