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:
parent
2b25fee520
commit
83a027d8be
2 changed files with 26 additions and 6 deletions
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue