Skip to main content

safe_tool

Function safe_tool 

Source
pub fn safe_tool<F, Fut>(
    name: impl Into<CompactString>,
    description: impl Into<String>,
    parameters: Value,
    f: F,
) -> RegisteredTool
where F: Fn(Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<SafeToolResult>> + Send + 'static,
Expand description

RegisteredTool::text equivalent that wraps the body in a structured envelope. The body returns either:

  • Ok(envelope) produced by ok(data) / fail(code, msg, hint) — passed through
  • Ok(value) of any other Value — auto-wrapped as ok(value)
  • Err(crate::Error::ToolFail{..}) — converted to fail envelope with the carried code/hint
  • Err(other) — converted to {success:false, code:"internal", error: format_tool_error(...)}