MCPcopy Create free account
hub / github.com/AI45Lab/Code / with_config

Method with_config

core/src/memory.rs:114–139  ·  view source on GitHub ↗

Create a new agent memory system with custom configuration. If `config.prune_policy` is `Some`, a background Tokio task is spawned that periodically calls `store.prune()` at the configured interval.

(store: Arc<dyn MemoryStore>, config: MemoryConfig)

Source from the content-addressed store, hash-verified

112 /// If `config.prune_policy` is `Some`, a background Tokio task is spawned
113 /// that periodically calls `store.prune()` at the configured interval.
114 pub fn with_config(store: Arc<dyn MemoryStore>, config: MemoryConfig) -> Self {
115 if let Some(policy) = config.prune_policy.clone() {
116 let store_for_task = Arc::clone(&store);
117 let interval_secs = config.prune_interval_secs;
118 tokio::spawn(async move {
119 let mut ticker =
120 tokio::time::interval(std::time::Duration::from_secs(interval_secs));
121 ticker.tick().await; // skip the immediate first tick
122 loop {
123 ticker.tick().await;
124 if let Err(e) = store_for_task.prune(&policy).await {
125 tracing::warn!("memory prune failed: {e}");
126 }
127 }
128 });
129 }
130
131 Self {
132 store,
133 short_term: Arc::new(RwLock::new(VecDeque::new())),
134 working: Arc::new(RwLock::new(Vec::new())),
135 max_short_term: config.max_short_term,
136 max_working: config.max_working,
137 relevance_config: config.relevance,
138 }
139 }
140
141 pub(crate) fn score(&self, item: &MemoryItem, now: DateTime<Utc>) -> f32 {
142 let age_days = (now - item.timestamp).num_seconds() as f32 / 86400.0;

Callers 2

register_hookMethod · 0.45
register_hookMethod · 0.45

Calls 1

cloneMethod · 0.45

Tested by

no test coverage detected