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:
parent
f6ea659975
commit
fe7f636ad3
8 changed files with 124 additions and 189 deletions
|
|
@ -130,43 +130,19 @@ fn job_consolidation_agent(
|
|||
ctx.log_line("loading store");
|
||||
let mut store = crate::store::Store::load()?;
|
||||
|
||||
let label = if batch > 0 {
|
||||
format!("{} (batch={})", agent, batch)
|
||||
} else {
|
||||
agent.to_string()
|
||||
};
|
||||
ctx.log_line(&format!("building prompt: {}", label));
|
||||
|
||||
let agent_batch = super::prompts::agent_prompt(&store, &agent, batch)?;
|
||||
ctx.log_line(&format!("prompt: {} chars ({} nodes), calling Sonnet",
|
||||
agent_batch.prompt.len(), agent_batch.node_keys.len()));
|
||||
|
||||
let response = super::llm::call_sonnet("consolidate", &agent_batch.prompt)?;
|
||||
ctx.log_line(&format!("running agent: {} (batch={})", agent, batch));
|
||||
let result = super::knowledge::run_one_agent(&mut store, &agent, batch, "consolidate")?;
|
||||
|
||||
let ts = crate::store::format_datetime(crate::store::now_epoch())
|
||||
.replace([':', '-', 'T'], "");
|
||||
let report_key = format!("_consolidation-{}-{}", agent, ts);
|
||||
store.upsert_provenance(&report_key, &response,
|
||||
crate::store::Provenance::AgentConsolidate).ok();
|
||||
|
||||
// Parse and apply actions inline
|
||||
let actions = super::knowledge::parse_all_actions(&response);
|
||||
let mut applied = 0;
|
||||
for action in &actions {
|
||||
for action in &result.actions {
|
||||
if super::knowledge::apply_action(&mut store, action, &agent, &ts, 0) {
|
||||
applied += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
ctx.log_line(&format!("visit recording: {}", e));
|
||||
}
|
||||
}
|
||||
|
||||
ctx.log_line(&format!("done: {} actions ({} applied) → {}",
|
||||
actions.len(), applied, report_key));
|
||||
ctx.log_line(&format!("done: {} actions ({} applied)", result.actions.len(), applied));
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue