From 9d29e392a81d7b7ebaa373d95e2c8a58eb79474e Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Tue, 10 Mar 2026 22:57:02 -0400 Subject: [PATCH] agents: add DEMOTE action for redundancy cleanup New action type that halves a node's weight (min 0.05), enabling extractors to mark redundant nodes for decay without deleting them. Parser, apply logic, depth computation, and display all updated. --- poc-memory/src/agents/consolidate.rs | 2 ++ poc-memory/src/agents/knowledge.rs | 33 +++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/poc-memory/src/agents/consolidate.rs b/poc-memory/src/agents/consolidate.rs index 089a0ca..ce6d78a 100644 --- a/poc-memory/src/agents/consolidate.rs +++ b/poc-memory/src/agents/consolidate.rs @@ -231,6 +231,8 @@ pub fn apply_consolidation(store: &mut Store, do_apply: bool, report_key: Option println!(" WRITE {}", key), knowledge::ActionKind::Refine { key, .. } => println!(" REFINE {}", key), + knowledge::ActionKind::Demote { key } => + println!(" DEMOTE {}", key), } } println!("\nTo apply: poc-memory apply-consolidation --apply"); diff --git a/poc-memory/src/agents/knowledge.rs b/poc-memory/src/agents/knowledge.rs index 269bc2e..67dd264 100644 --- a/poc-memory/src/agents/knowledge.rs +++ b/poc-memory/src/agents/knowledge.rs @@ -48,6 +48,9 @@ pub enum ActionKind { key: String, content: String, }, + Demote { + key: String, + }, } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] @@ -161,10 +164,27 @@ pub fn parse_refines(text: &str) -> Vec { .collect() } +pub fn parse_demotes(text: &str) -> Vec { + let re = Regex::new(r"(?m)^DEMOTE\s+(\S+)").unwrap(); + re.captures_iter(text) + .map(|cap| Action { + kind: ActionKind::Demote { + key: cap[1].to_string(), + }, + confidence: Confidence::Medium, + weight: 0.5, + depth: -1, + applied: None, + rejected_reason: None, + }) + .collect() +} + pub fn parse_all_actions(text: &str) -> Vec { let mut actions = parse_write_nodes(text); actions.extend(parse_links(text)); actions.extend(parse_refines(text)); + actions.extend(parse_demotes(text)); actions } @@ -223,7 +243,7 @@ fn agent_base_depth(agent: &str) -> Option { pub fn compute_action_depth(db: &DepthDb, action: &Action, agent: &str) -> i32 { match &action.kind { - ActionKind::Link { .. } => -1, + ActionKind::Link { .. } | ActionKind::Demote { .. } => -1, ActionKind::Refine { key, .. } => db.get(key), ActionKind::WriteNode { covers, .. } => { if !covers.is_empty() { @@ -307,6 +327,14 @@ pub fn apply_action( let stamped = stamp_content(content, agent, timestamp, depth); store.upsert_provenance(key, &stamped, provenance).is_ok() } + ActionKind::Demote { key } => { + if let Some(node) = store.nodes.get_mut(key) { + node.weight = (node.weight * 0.5).max(0.05); + true + } else { + false + } + } } } @@ -696,6 +724,9 @@ fn run_cycle( ActionKind::Refine { key, .. } => { eprintln!(" REFINE {} depth={}", key, depth); } + ActionKind::Demote { key } => { + eprintln!(" DEMOTE {}", key); + } } if apply_action(&mut store, action, agent_name, ×tamp, depth) {