Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn label(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters(&self) -> Value;
    fn execute<'life0, 'life1, 'async_trait>(
        &'life0 self,
        tool_call_id: &'life1 str,
        input: Value,
        on_update: Option<Box<dyn Fn(ToolUpdate) + Send + Sync>>,
    ) -> Pin<Box<dyn Future<Output = Result<ToolOutput>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn is_read_only(&self) -> bool { ... }
}
Expand description

A tool that can be executed by the agent.

Required Methods§

Source

fn name(&self) -> &str

Get the tool name.

Source

fn label(&self) -> &str

Get the tool label (display name).

Source

fn description(&self) -> &str

Get the tool description.

Source

fn parameters(&self) -> Value

Get the tool parameters as JSON Schema.

Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, tool_call_id: &'life1 str, input: Value, on_update: Option<Box<dyn Fn(ToolUpdate) + Send + Sync>>, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the tool.

Tools may call on_update to stream incremental results (e.g. while a long-running bash command is still producing output). The final return value is a ToolOutput which is persisted into the session as a tool result message.

Provided Methods§

Source

fn is_read_only(&self) -> bool

Whether the tool is read-only and safe to execute in parallel with other read-only tools.

Defaults to false (safe/sequential).

Implementors§