tools: each module owns its Tool list, no duplication

Each tool module exports its own tools() returning Vec<Tool>.
mod.rs::tools() chains them. Individual _def() and handler functions
are pub(super), not exported. Aggregate definitions derived from
the Tool lists.

- memory: memory_tools(), journal_tools()
- channels: tools()
- control: tools()
- mod.rs: just chains + adds file/bash/web/vision

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-04 15:22:03 -04:00 committed by Kent Overstreet
parent aa7511d110
commit 6d6da07f91
4 changed files with 91 additions and 81 deletions

View file

@ -202,56 +202,22 @@ pub async fn dispatch_shared(
/// Return all registered tools with definitions + handlers.
pub fn tools() -> Vec<Tool> {
vec![
let mut all = vec![
// File tools
Tool { def: read::definition(), handler: |_a, v| Box::pin(async move { read::read_file(&v) }) },
Tool { def: write::definition(), handler: |_a, v| Box::pin(async move { write::write_file(&v) }) },
Tool { def: edit::definition(), handler: |_a, v| Box::pin(async move { edit::edit_file(&v) }) },
Tool { def: grep::definition(), handler: |_a, v| Box::pin(async move { grep::grep(&v) }) },
Tool { def: glob::definition(), handler: |_a, v| Box::pin(async move { glob::glob_search(&v) }) },
// Execution tools
Tool { def: bash::definition(), handler: |_a, v| Box::pin(async move { bash::run_bash(&v).await }) },
Tool { def: web::fetch_definition(), handler: |_a, v| Box::pin(async move { web::web_fetch(&v).await }) },
Tool { def: web::search_definition(), handler: |_a, v| Box::pin(async move { web::web_search(&v).await }) },
// Vision
Tool { def: vision::definition(), handler: |_a, v| Box::pin(async move { vision::view_image_text(&v) }) },
// Memory tools
Tool { def: memory::render_def(), handler: |_a, v| Box::pin(async move { memory::render(&v) }) },
Tool { def: memory::write_def(), handler: |_a, v| Box::pin(async move { memory::write(&v) }) },
Tool { def: memory::search_def(), handler: |_a, v| Box::pin(async move { memory::search(&v) }) },
Tool { def: memory::links_def(), handler: |_a, v| Box::pin(async move { memory::links(&v) }) },
Tool { def: memory::link_set_def(), handler: |_a, v| Box::pin(async move { memory::link_set(&v) }) },
Tool { def: memory::link_add_def(), handler: |_a, v| Box::pin(async move { memory::link_add(&v) }) },
Tool { def: memory::used_def(), handler: |_a, v| Box::pin(async move { memory::used(&v) }) },
Tool { def: memory::weight_set_def(), handler: |_a, v| Box::pin(async move { memory::weight_set(&v) }) },
Tool { def: memory::rename_def(), handler: |_a, v| Box::pin(async move { memory::rename(&v) }) },
Tool { def: memory::supersede_def(), handler: |_a, v| Box::pin(async move { memory::supersede(&v) }) },
Tool { def: memory::query_def(), handler: |_a, v| Box::pin(async move { memory::query(&v) }) },
Tool { def: memory::output_def(), handler: |_a, v| Box::pin(async move { memory::output(&v) }) },
// Channel tools
Tool { def: channels::definitions()[0].clone(), handler: |_a, v| Box::pin(async move { channels::channel_list().await }) },
Tool { def: channels::definitions()[1].clone(), handler: |_a, v| Box::pin(async move { channels::channel_recv(&v).await }) },
Tool { def: channels::definitions()[2].clone(), handler: |_a, v| Box::pin(async move { channels::channel_send(&v).await }) },
Tool { def: channels::definitions()[3].clone(), handler: |_a, v| Box::pin(async move { channels::channel_notifications().await }) },
// Control tools
Tool { def: control::definitions()[0].clone(),
handler: |_a, _v| Box::pin(async { Ok("Pausing autonomous behavior. Only user input will wake you.".into()) }) },
Tool { def: control::definitions()[1].clone(),
handler: |_a, v| Box::pin(async move {
let model = v.get("model").and_then(|v| v.as_str()).unwrap_or("");
Ok(format!("Switching to model: {}", model))
}) },
Tool { def: control::definitions()[2].clone(),
handler: |_a, v| Box::pin(async move {
let msg = v.get("message").and_then(|v| v.as_str()).unwrap_or("(yielding to user)");
Ok(msg.to_string())
}) },
]
];
all.extend(memory::memory_tools());
all.extend(channels::tools());
all.extend(control::tools());
all
}
/// Return all tool definitions (extracted from tools()).
@ -261,9 +227,10 @@ pub fn definitions() -> Vec<ToolDef> {
/// Return memory + journal tool definitions only.
pub fn memory_and_journal_definitions() -> Vec<ToolDef> {
let mut defs = memory::definitions();
defs.extend(memory::journal_definitions());
defs
memory::memory_tools().into_iter()
.chain(memory::journal_tools())
.map(|t| t.def)
.collect()
}
/// Create a short summary of tool args for the tools pane header.