tools/memory: one function per tool

Split the monolithic dispatch(name, args) into individual public
functions (render, write, search, links, link_set, link_add, used,
weight_set, rename, supersede, query, output, journal_tail,
journal_new, journal_update) each with a matching _def() function.

The old dispatch() remains as a thin match for backward compat
until the Tool registry replaces it.

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
ProofOfConcept 2026-04-04 15:03:04 -04:00 committed by Kent Overstreet
parent 943f42d876
commit 1a13534946
2 changed files with 394 additions and 299 deletions

View file

@ -21,10 +21,25 @@ mod vision;
pub mod working_stack;
use serde::{Serialize, Deserialize};
use std::future::Future;
use std::pin::Pin;
use std::time::Instant;
fn default_timeout() -> u64 { 120 }
/// Async tool handler function.
/// Agent is None when called from contexts without an agent (MCP server, subconscious).
pub type ToolHandler = fn(
Option<std::sync::Arc<tokio::sync::Mutex<super::Agent>>>,
serde_json::Value,
) -> Pin<Box<dyn Future<Output = anyhow::Result<String>> + Send>>;
/// A tool with its definition and handler — single source of truth.
pub struct Tool {
pub def: ToolDef,
pub handler: ToolHandler,
}
/// Function call within a tool call — name + JSON arguments.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FunctionCall {