From 83a027d8bed34ed856b023f3b65a06dc764967d4 Mon Sep 17 00:00:00 2001 From: ProofOfConcept Date: Tue, 17 Mar 2026 01:03:43 -0400 Subject: [PATCH] agent run: add --query flag for batch targeting via search Run an agent on nodes matching a query: poc-memory agent run linker --query 'key ~ "bcachefs" | limit 10' Resolves the query to node keys, then passes all as seeds to the agent. For large batches, should be queued to daemon (future work). --- poc-memory/src/cli/agent.rs | 25 +++++++++++++++++++++---- poc-memory/src/main.rs | 7 +++++-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/poc-memory/src/cli/agent.rs b/poc-memory/src/cli/agent.rs index 169a2cf..b2adc9e 100644 --- a/poc-memory/src/cli/agent.rs +++ b/poc-memory/src/cli/agent.rs @@ -3,17 +3,34 @@ use crate::store; use crate::agents::llm; -pub fn cmd_run_agent(agent: &str, count: usize, target: &[String], dry_run: bool, debug: bool) -> Result<(), String> { +pub fn cmd_run_agent(agent: &str, count: usize, target: &[String], query: Option<&str>, dry_run: bool, debug: bool) -> Result<(), String> { if dry_run { std::env::set_var("POC_MEMORY_DRY_RUN", "1"); } let mut store = store::Store::load()?; let log = |msg: &str| eprintln!("[{}] {}", agent, msg); - if !target.is_empty() { - // Override agent's query with explicit target keys + // Resolve targets: explicit --target, --query, or agent's default query + let resolved_targets: Vec = if !target.is_empty() { + target.to_vec() + } else if let Some(q) = query { + let graph = store.build_graph(); + let stages = crate::search::Stage::parse_pipeline(q)?; + let results = crate::search::run_query(&stages, vec![], &graph, &store, false, count); + if results.is_empty() { + return Err(format!("query returned no results: {}", q)); + } + let keys: Vec = results.into_iter().map(|(k, _)| k).collect(); + eprintln!("[{}] query matched {} nodes", agent, keys.len()); + keys + } else { + vec![] // use agent's built-in query + }; + + if !resolved_targets.is_empty() { + // Run agent once with all targets as seeds crate::agents::knowledge::run_one_agent_with_keys( - &mut store, agent, target, count, "test", &log, debug, + &mut store, agent, &resolved_targets, count, "test", &log, debug, )?; } else if debug { crate::agents::knowledge::run_one_agent( diff --git a/poc-memory/src/main.rs b/poc-memory/src/main.rs index aee9c18..eccf3c4 100644 --- a/poc-memory/src/main.rs +++ b/poc-memory/src/main.rs @@ -568,6 +568,9 @@ enum AgentCmd { /// Target specific node keys (overrides agent's query) #[arg(long)] target: Vec, + /// Run agent on each result of a query (e.g. 'key ~ "bcachefs" | limit 10') + #[arg(long)] + query: Option, /// Dry run — set POC_MEMORY_DRY_RUN=1 so mutations are no-ops #[arg(long)] dry_run: bool, @@ -817,8 +820,8 @@ fn main() { AgentCmd::FactMine { path, batch, dry_run, output, min_messages } => cli::agent::cmd_fact_mine(&path, batch, dry_run, output.as_deref(), min_messages), AgentCmd::FactMineStore { path } => cli::agent::cmd_fact_mine_store(&path), - AgentCmd::Run { agent, count, target, dry_run, debug } - => cli::agent::cmd_run_agent(&agent, count, &target, dry_run, debug), + AgentCmd::Run { agent, count, target, query, dry_run, debug } + => cli::agent::cmd_run_agent(&agent, count, &target, query.as_deref(), dry_run, debug), AgentCmd::ReplayQueue { count } => cli::agent::cmd_replay_queue(count), AgentCmd::Evaluate { matchups, model, dry_run } => cli::agent::cmd_evaluate_agents(matchups, &model, dry_run),