Skip to main content

make_handler

Function make_handler 

Source
pub fn make_handler<F, Fut>(
    f: F,
) -> Box<dyn Fn(Value) -> BoxFuture<'static, Result<Value, ToolError>> + Send + Sync>
where F: Fn(Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, ToolError>> + Send + 'static,
Expand description

Helper to wrap an async fn or closure into the boxed handler type required by ToolDef.

§Example

use ferro_ai::tools::{make_handler, ToolDef, ToolError};

let def = ToolDef {
    name: "greet".into(),
    description: "Greet a user by name".into(),
    parameters_schema: serde_json::json!({"type":"object","properties":{"name":{"type":"string"}},"required":["name"]}),
    handler: make_handler(|input| async move {
        let name = input["name"].as_str().unwrap_or("world");
        Ok(serde_json::json!({"greeting": format!("Hello, {name}!")}))
    }),
};