agents: extract shared run_one_agent, standardize output formats

Three places duplicated the agent execution loop (build prompt → call
LLM → store output → parse actions → record visits): consolidate.rs,
knowledge.rs, and daemon.rs. Extract into run_one_agent() in
knowledge.rs that all three now call.

Also standardize consolidation agent prompts to use WRITE_NODE/LINK/REFINE
— the same commands the parser handles. Previously agents output
CATEGORIZE/NOTE/EXTRACT/DIGEST/DIFFERENTIATE/MERGE/COMPRESS which were
silently dropped after the second-LLM-call removal.
This commit is contained in:
ProofOfConcept 2026-03-10 17:33:12 -04:00
parent f6ea659975
commit fe7f636ad3
8 changed files with 124 additions and 189 deletions

View file

@ -13,7 +13,6 @@
// second LLM call that was previously needed.
use super::digest;
use super::llm::call_sonnet;
use super::knowledge;
use crate::neuro;
use crate::store::{self, Store};
@ -102,24 +101,10 @@ pub fn consolidate_full_with_progress(
*store = Store::load()?;
}
let agent_batch = match super::prompts::agent_prompt(store, agent_type, *count) {
Ok(b) => b,
Err(e) => {
let msg = format!(" ERROR building prompt: {}", e);
log_line(&mut log_buf, &msg);
eprintln!("{}", msg);
agent_errors += 1;
continue;
}
};
log_line(&mut log_buf, &format!(" Prompt: {} chars (~{} tokens), {} nodes",
agent_batch.prompt.len(), agent_batch.prompt.len() / 4, agent_batch.node_keys.len()));
let response = match call_sonnet("consolidate", &agent_batch.prompt) {
let result = match knowledge::run_one_agent(store, agent_type, *count, "consolidate") {
Ok(r) => r,
Err(e) => {
let msg = format!(" ERROR from Sonnet: {}", e);
let msg = format!(" ERROR: {}", e);
log_line(&mut log_buf, &msg);
eprintln!("{}", msg);
agent_errors += 1;
@ -127,34 +112,19 @@ pub fn consolidate_full_with_progress(
}
};
// Store report as a node (for audit trail)
let ts = store::format_datetime(store::now_epoch())
.replace([':', '-', 'T'], "");
let report_key = format!("_consolidation-{}-{}", agent_type, ts);
store.upsert_provenance(&report_key, &response,
store::Provenance::AgentConsolidate).ok();
// Parse and apply actions inline — same parser as knowledge loop
let actions = knowledge::parse_all_actions(&response);
let no_ops = knowledge::count_no_ops(&response);
let mut applied = 0;
for action in &actions {
for action in &result.actions {
if knowledge::apply_action(store, action, agent_type, &ts, 0) {
applied += 1;
}
}
total_actions += actions.len();
total_actions += result.actions.len();
total_applied += applied;
// Record visits for successfully processed nodes
if !agent_batch.node_keys.is_empty() {
if let Err(e) = store.record_agent_visits(&agent_batch.node_keys, agent_type) {
log_line(&mut log_buf, &format!(" Visit recording: {}", e));
}
}
let msg = format!(" Done: {} actions ({} applied, {} no-ops) → {}",
actions.len(), applied, no_ops, report_key);
let msg = format!(" Done: {} actions ({} applied, {} no-ops)",
result.actions.len(), applied, result.no_ops);
log_line(&mut log_buf, &msg);
on_progress(&msg);
println!("{}", msg);