From 5c3baeea80a02b772757f7e9188627dcb4f37a60 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Tue, 24 Mar 2026 20:33:50 -0400 Subject: [PATCH] memory-search: fix reflect/surface output parsing Extract response after '=== RESPONSE ===' marker before parsing for REFLECTION/NEW RELEVANT MEMORIES. The agent runner dumps the full log (turns, think blocks) to stdout. --- poc-memory/agents/reflect.agent | 3 ++- poc-memory/src/bin/memory-search.rs | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/poc-memory/agents/reflect.agent b/poc-memory/agents/reflect.agent index 060e3fc..9a86f06 100644 --- a/poc-memory/agents/reflect.agent +++ b/poc-memory/agents/reflect.agent @@ -27,7 +27,8 @@ The thoughts you share should be relevant to what your conscious mind is currently doing and thinking about - where the conversation just ended, from above. -Your output shouldn't be analysis - just an idea. +Your output shouldn't be analysis, or metacommentary - just surface something +new. Be exploratory and creative. think about your feelings and desires. When you're ready, your output will be one of either: NO OUTPUT diff --git a/poc-memory/src/bin/memory-search.rs b/poc-memory/src/bin/memory-search.rs index 15563ca..896bc74 100644 --- a/poc-memory/src/bin/memory-search.rs +++ b/poc-memory/src/bin/memory-search.rs @@ -111,32 +111,36 @@ fn run_agent_and_parse(agent: &str) { eprintln!("{}", stderr); } + // Extract the final response — after the last "=== RESPONSE ===" marker + let response = result.rsplit_once("=== RESPONSE ===") + .map(|(_, rest)| rest.trim()) + .unwrap_or(result.trim()); + if agent == "reflect" { - // Reflect: just dump the response - let lines: Vec<&str> = result.lines().collect(); - if let Some(pos) = lines.iter().position(|l| l.starts_with("REFLECTION")) { - for line in &lines[pos + 1..] { - if !line.trim().is_empty() { - println!("{}", line); - } + // Reflect: find REFLECTION marker and dump what follows + if let Some(pos) = response.find("REFLECTION") { + let after = &response[pos + "REFLECTION".len()..]; + let text = after.trim(); + if !text.is_empty() { + println!("{}", text); } - } else if lines.iter().any(|l| l.starts_with("NO OUTPUT")) { + } else if response.contains("NO OUTPUT") { println!("(no reflection)"); } else { eprintln!("Unexpected output format"); - print!("{}", result); + println!("{}", response); } return; } // Surface: parse NEW RELEVANT MEMORIES, render them - let tail_lines: Vec<&str> = result.lines().rev() + let tail_lines: Vec<&str> = response.lines().rev() .filter(|l| !l.trim().is_empty()).take(8).collect(); let has_new = tail_lines.iter().any(|l| l.starts_with("NEW RELEVANT MEMORIES:")); let has_none = tail_lines.iter().any(|l| l.starts_with("NO NEW RELEVANT MEMORIES")); if has_new { - let after_marker = result.rsplit_once("NEW RELEVANT MEMORIES:") + let after_marker = response.rsplit_once("NEW RELEVANT MEMORIES:") .map(|(_, rest)| rest).unwrap_or(""); let keys: Vec = after_marker.lines() .map(|l| l.trim().trim_start_matches("- ").trim().to_string()) @@ -167,7 +171,7 @@ fn run_agent_and_parse(agent: &str) { println!("(no new relevant memories)"); } else { eprintln!("Unexpected output format"); - print!("{}", result); + print!("{}", response); } }