tools: add memory_query for structured graph queries
Exposes the full query language as a tool: filtering, sorting, field
selection, neighbor walks. Examples:
degree > 10 | sort weight | limit 5
neighbors('identity') | select strength
key ~ 'journal.*' | count
Also added query_to_string() in the parser so queries return strings
instead of printing to stdout. Updated memory-instructions-core to
list all current tools (added memory_query and journal, removed
CLI commands section and nonexistent memory_search_content).
Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
9a09a665fb
commit
a865285313
2 changed files with 57 additions and 0 deletions
|
|
@ -38,6 +38,11 @@ pub fn definitions() -> Vec<ToolDef> {
|
|||
ToolDef::new("memory_supersede",
|
||||
"Mark a node as superseded by another (sets weight to 0.01).",
|
||||
json!({"type":"object","properties":{"old_key":{"type":"string"},"new_key":{"type":"string"},"reason":{"type":"string"}},"required":["old_key","new_key"]})),
|
||||
ToolDef::new("memory_query",
|
||||
"Run a structured query against the memory graph. Supports filtering, \
|
||||
sorting, field selection. Examples: \"degree > 10 | sort weight | limit 5\", \
|
||||
\"neighbors('identity') | select strength\", \"key ~ 'journal.*' | count\"",
|
||||
json!({"type":"object","properties":{"query":{"type":"string","description":"Query expression"}},"required":["query"]})),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -102,6 +107,13 @@ pub fn dispatch(name: &str, args: &serde_json::Value, provenance: Option<&str>)
|
|||
store.save().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
Ok(format!("superseded {} → {} ({})", old_key, new_key, reason))
|
||||
}
|
||||
"memory_query" => {
|
||||
let query = get_str(args, "query")?;
|
||||
let store = Store::load().map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
let graph = store.build_graph();
|
||||
crate::query_parser::query_to_string(&store, &graph, query)
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))
|
||||
}
|
||||
_ => anyhow::bail!("Unknown memory tool: {}", name),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue