Skip to main content

Tool

Trait Tool 

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

    // Provided methods
    fn dynamic_description(&self) -> Option<String> { ... }
    fn check_permissions<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _params: &'life1 Value,
        _context: &'life2 ToolContext,
    ) -> Pin<Box<dyn Future<Output = PermissionCheckResult> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn get_definition(&self) -> ToolDefinition { ... }
    fn options(&self) -> ToolOptions { ... }
}
Expand description

Tool trait - the core interface for all tools

All tools in the system must implement this trait. It provides:

  • Identification (name, description)
  • Input schema for validation
  • Async execution
  • Permission checking
  • Configuration options

Requirements: 1.1, 1.2

Required Methods§

Source

fn name(&self) -> &str

Returns the unique name of the tool

This name is used for registration and lookup in the tool registry.

Source

fn description(&self) -> &str

Returns a human-readable description of the tool

This description is provided to the LLM to help it understand when and how to use the tool.

Source

fn input_schema(&self) -> Value

Returns the JSON Schema for the tool’s input parameters

This schema is used for:

  • Input validation before execution
  • Providing parameter information to the LLM
Source

fn execute<'life0, 'life1, 'async_trait>( &'life0 self, params: Value, context: &'life1 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the tool with the given parameters and context

This is the main entry point for tool execution.

§Arguments
  • params - The input parameters as a JSON value
  • context - The execution context containing environment info
§Returns
  • Ok(ToolResult) - The execution result
  • Err(ToolError) - If execution fails

Provided Methods§

Source

fn dynamic_description(&self) -> Option<String>

Returns a dynamically generated description of the tool

Override this method when the tool description needs to include dynamic content (e.g., available skills, current state). Default implementation returns None, falling back to description().

Source

fn check_permissions<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _params: &'life1 Value, _context: &'life2 ToolContext, ) -> Pin<Box<dyn Future<Output = PermissionCheckResult> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Check permissions before executing the tool

This method is called before execute to determine if the tool should be allowed to run with the given parameters.

Default implementation allows all executions.

§Arguments
  • params - The input parameters to check
  • context - The execution context
§Returns

A PermissionCheckResult indicating whether to allow, deny, or ask

Source

fn get_definition(&self) -> ToolDefinition

Get the tool definition for LLM consumption

Returns a ToolDefinition containing the name, description, and input schema in a format suitable for LLM tool calling.

Default implementation constructs from name(), dynamic_description() or description(), and input_schema(). Prefers dynamic_description() if available.

Source

fn options(&self) -> ToolOptions

Get the tool’s configuration options

Returns the ToolOptions for this tool, including retry settings, timeout configuration, etc.

Default implementation returns default options.

Implementors§