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§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Returns the unique name of the tool
This name is used for registration and lookup in the tool registry.
Sourcefn description(&self) -> &str
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.
Sourcefn input_schema(&self) -> Value
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
Sourcefn 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,
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 valuecontext- The execution context containing environment info
§Returns
Ok(ToolResult)- The execution resultErr(ToolError)- If execution fails
Provided Methods§
Sourcefn dynamic_description(&self) -> Option<String>
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().
Sourcefn 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 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 checkcontext- The execution context
§Returns
A PermissionCheckResult indicating whether to allow, deny, or ask
Sourcefn get_definition(&self) -> ToolDefinition
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.
Sourcefn options(&self) -> ToolOptions
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.