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.
This commit is contained in:
parent
e93e682359
commit
5c3baeea80
2 changed files with 18 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<String> = 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue