Skip to main content

tool

Function tool 

Source
pub fn tool<I, O, F, Fut>(
    name: &str,
    description: &str,
    effect: Effect,
    f: F,
) -> FnTool<I, O, F>
where I: DeserializeOwned + JsonSchema + Send + 'static, O: Serialize + Send + 'static, F: Fn(I, ToolCtx) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<O, ToolError>> + Send + 'static,
Expand description

Builds a typed tool from an async function. The JSON schema shown to the model is derived from I, and model input is validated against it.

ⓘ
#[derive(Deserialize, JsonSchema)]
struct GetOrder { order_id: String }

let get_order = tool("get_order", "Look up an order", Effect::Read,
    |i: GetOrder, _ctx| async move { Ok(json!({"id": i.order_id})) });