organize: fine-grained agent logging + cluster size cap
Add progress callback to run_one_agent and run_and_apply so callers can see: prompt size, node list, LLM call timing, parsed action count, and per-action applied/skipped status. Daemon writes these to the persistent event log via log_event. Cap organize cluster to 20 nodes - 126 nodes produced a 682KB prompt that timed out every time. Agent has tools to explore further if needed. Restore general query for production runs.
This commit is contained in:
parent
01aba4c12b
commit
4cacfa7599
4 changed files with 56 additions and 6 deletions
|
|
@ -579,13 +579,33 @@ pub fn run_and_apply(
|
|||
batch_size: usize,
|
||||
llm_tag: &str,
|
||||
) -> Result<(usize, usize), String> {
|
||||
let result = run_one_agent(store, agent_name, batch_size, llm_tag)?;
|
||||
run_and_apply_with_log(store, agent_name, batch_size, llm_tag, &|_| {})
|
||||
}
|
||||
|
||||
pub fn run_and_apply_with_log(
|
||||
store: &mut Store,
|
||||
agent_name: &str,
|
||||
batch_size: usize,
|
||||
llm_tag: &str,
|
||||
log: &dyn Fn(&str),
|
||||
) -> Result<(usize, usize), String> {
|
||||
let result = run_one_agent(store, agent_name, batch_size, llm_tag, log)?;
|
||||
let actions = resolve_action_names(store, result.actions);
|
||||
let ts = store::compact_timestamp();
|
||||
let mut applied = 0;
|
||||
for action in &actions {
|
||||
let desc = match &action.kind {
|
||||
ActionKind::WriteNode { key, .. } => format!("WRITE {}", key),
|
||||
ActionKind::Refine { key, .. } => format!("REFINE {}", key),
|
||||
ActionKind::Link { source, target } => format!("LINK {} → {}", source, target),
|
||||
ActionKind::Demote { key } => format!("DEMOTE {}", key),
|
||||
ActionKind::Delete { key } => format!("DELETE {}", key),
|
||||
};
|
||||
if apply_action(store, action, agent_name, &ts, 0) {
|
||||
log(&format!("applied: {}", desc));
|
||||
applied += 1;
|
||||
} else {
|
||||
log(&format!("skipped: {}", desc));
|
||||
}
|
||||
}
|
||||
Ok((actions.len(), applied))
|
||||
|
|
@ -600,13 +620,29 @@ pub fn run_one_agent(
|
|||
agent_name: &str,
|
||||
batch_size: usize,
|
||||
llm_tag: &str,
|
||||
log: &dyn Fn(&str),
|
||||
) -> Result<AgentResult, String> {
|
||||
let def = super::defs::get_def(agent_name)
|
||||
.ok_or_else(|| format!("no .agent file for {}", agent_name))?;
|
||||
|
||||
log("building prompt");
|
||||
let agent_batch = super::defs::run_agent(store, &def, batch_size)?;
|
||||
|
||||
let prompt_kb = agent_batch.prompt.len() / 1024;
|
||||
let tools_desc = if def.tools.is_empty() { "no tools".into() }
|
||||
else { format!("{} tools", def.tools.len()) };
|
||||
log(&format!("prompt {}KB, model={}, {}, {} nodes",
|
||||
prompt_kb, def.model, tools_desc, agent_batch.node_keys.len()));
|
||||
for key in &agent_batch.node_keys {
|
||||
log(&format!(" node: {}", key));
|
||||
}
|
||||
|
||||
log("calling LLM");
|
||||
let output = llm::call_for_def(&def, &agent_batch.prompt)?;
|
||||
|
||||
let output_kb = output.len() / 1024;
|
||||
log(&format!("response {}KB", output_kb));
|
||||
|
||||
// Store raw output for audit trail
|
||||
let ts = store::compact_timestamp();
|
||||
let report_key = format!("_{}-{}-{}", llm_tag, agent_name, ts);
|
||||
|
|
@ -616,6 +652,8 @@ pub fn run_one_agent(
|
|||
let actions = parse_all_actions(&output);
|
||||
let no_ops = count_no_ops(&output);
|
||||
|
||||
log(&format!("parsed {} actions, {} no-ops", actions.len(), no_ops));
|
||||
|
||||
// Record visits for processed nodes
|
||||
if !agent_batch.node_keys.is_empty() {
|
||||
store.record_agent_visits(&agent_batch.node_keys, agent_name).ok();
|
||||
|
|
@ -889,7 +927,7 @@ fn run_cycle(
|
|||
for agent_name in &agent_names {
|
||||
eprintln!("\n --- {} (n={}) ---", agent_name, config.batch_size);
|
||||
|
||||
let result = match run_one_agent(&mut store, agent_name, config.batch_size, "knowledge") {
|
||||
let result = match run_one_agent(&mut store, agent_name, config.batch_size, "knowledge", &|msg| eprintln!(" {}", msg)) {
|
||||
Ok(r) => r,
|
||||
Err(e) => {
|
||||
eprintln!(" ERROR: {}", e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue