Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters(&self) -> Value;
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        args: &'life1 Value,
        ctx: &'life2 ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<ToolOutput>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn definition(&self) -> ToolDefinition { ... }
    fn capabilities(&self, _args: &Value) -> ToolCapabilities { ... }
    fn requires_confirmation(&self, _args: &Value) -> bool { ... }
}
Expand description

Tool trait - the core abstraction for all tools

Implement this trait to create custom tools that can be registered with the ToolRegistry.

Required Methods§

Source

fn name(&self) -> &str

Tool name (must be unique within registry)

Source

fn description(&self) -> &str

Human-readable description for LLM

Source

fn parameters(&self) -> Value

JSON Schema for tool parameters

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, args: &'life1 Value, ctx: &'life2 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute the tool with given arguments

Provided Methods§

Source

fn definition(&self) -> ToolDefinition

Complete model-facing definition for this tool.

Most tools have static metadata and use this default. Registry-backed tools can override it to build a definition from live runtime state without leaking owned strings through description().

Source

fn capabilities(&self, _args: &Value) -> ToolCapabilities

Scheduling and result capabilities for this specific invocation.

Source

fn requires_confirmation(&self, _args: &Value) -> bool

Whether tool-owned metadata requires this invocation to pass through HITL even when the host permission policy would otherwise allow it.

This is an escalation-only hint. The invocation gateway still applies the host permission policy first, so a tool can never use this hook to weaken an Ask or Deny decision.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§