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).
This commit is contained in:
ProofOfConcept 2026-03-17 01:03:43 -04:00
parent 2b25fee520
commit 83a027d8be
2 changed files with 26 additions and 6 deletions

View file

@ -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<String> = 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<String> = 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(

View file

@ -568,6 +568,9 @@ enum AgentCmd {
/// Target specific node keys (overrides agent's query)
#[arg(long)]
target: Vec<String>,
/// Run agent on each result of a query (e.g. 'key ~ "bcachefs" | limit 10')
#[arg(long)]
query: Option<String>,
/// 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),