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 call<'life0, 'async_trait>(
        &'life0 self,
        args: Value,
    ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn describe_call(&self, args: &Value) -> String { ... }
    fn needs_approval(&self, _args: &Value) -> bool { ... }
    fn call_scoped<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        args: Value,
        _scope: &'life1 CallScope<'life2>,
    ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}

Required Methods§

Source

fn name(&self) -> &str

Source

fn description(&self) -> &str

Source

fn parameters(&self) -> Value

JSON Schema for the arguments object.

Source

fn call<'life0, 'async_trait>( &'life0 self, args: Value, ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Provided Methods§

Source

fn describe_call(&self, args: &Value) -> String

Human-readable one-liner shown when asking for approval.

Source

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

Whether this particular call is put to the Approver under Policy::Ask. Every call is, unless a tool says otherwise: the answer is per call because one tool can have a side-effect-free form (the script tool’s listing) beside a form that runs code. deny and disabled are not affected — they never run anything.

Source

fn call_scoped<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, args: Value, _scope: &'life1 CallScope<'life2>, ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

call for a tool that needs to know which run it is part of: who may be asked, which session it belongs to, how many children the run has started. Almost no tool does, so the default ignores the scope.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§