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

    // Provided methods
    fn mutability(&self) -> ToolMutability { ... }
    fn call_mutability(&self, _args: &Value) -> ToolMutability { ... }
    fn concurrency_safe(&self) -> bool { ... }
    fn call_concurrency_safe(&self, _args: &Value) -> bool { ... }
    fn execute_with_context<'life0, 'life1, 'async_trait>(
        &'life0 self,
        args: Value,
        _ctx: ToolExecutionContext<'life1>,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn to_schema(&self) -> ToolSchema { ... }
}
Expand description

Trait for implementing executable tools.

All tools must implement this trait to be registered with the tool registry.

§Required Methods

  • name() - Unique tool identifier
  • description() - Human-readable tool description
  • parameters_schema() - JSON Schema for tool parameters
  • execute() - Async tool execution logic

§Provided Methods

  • to_schema() - Convert tool to LLM-compatible schema

§Example

struct ReadFileTool;

#[async_trait]
impl Tool for ReadFileTool {
    fn name(&self) -> &str {
        "read_file"
    }

    fn description(&self) -> &str {
        "Read file contents from disk"
    }

    fn parameters_schema(&self) -> serde_json::Value {
        json!({
            "type": "object",
            "properties": {
                "path": {"type": "string"}
            },
            "required": ["path"]
        })
    }

    async fn execute(&self, args: Value) -> Result<ToolResult, ToolError> {
        let path = args["path"].as_str().unwrap();
        let content = tokio::fs::read_to_string(path).await?;
        Ok(ToolResult {
            success: true,
            result: content,
            display_preference: None,
        })
    }
}

Required Methods§

Source

fn name(&self) -> &str

Source

fn description(&self) -> &str

Human-readable tool description for LLM.

Source

fn parameters_schema(&self) -> Value

JSON Schema for tool parameters.

Source

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

Execute the tool with given arguments.

Provided Methods§

Source

fn mutability(&self) -> ToolMutability

Declares whether this tool is read-only or mutating for orchestration and parallel scheduling decisions. Defaults to mutating to stay conservative.

Source

fn call_mutability(&self, _args: &Value) -> ToolMutability

Args-aware mutability hook. Defaults to the static mutability declaration.

Source

fn concurrency_safe(&self) -> bool

Declares whether this tool can safely run in parallel with other read-only tools. Defaults to false so tools remain serialized unless they opt in explicitly.

Source

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

Args-aware parallel-safety hook. Defaults to the static declaration.

Source

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, _ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Execute the tool with a streaming-capable context.

Default implementation falls back to execute() for tools that don’t need streaming.

Source

fn to_schema(&self) -> ToolSchema

Convert tool to LLM-compatible schema.

Creates a ToolSchema suitable for LLM function calling.

Implementations on Foreign Types§

Source§

impl Tool for BashTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, BashTool: 'async_trait,

Source§

impl Tool for BashOutputTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for ConclusionWithOptionsTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for EditTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, EditTool: 'async_trait,

Source§

impl Tool for EnterPlanModeTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for ExitPlanModeTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for GetFileInfoTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for GlobTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, GlobTool: 'async_trait,

Source§

impl Tool for GrepTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, GrepTool: 'async_trait,

Source§

impl Tool for JsReplTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for KillShellTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for SessionNoteTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn call_mutability(&self, args: &Value) -> ToolMutability

Source§

fn call_concurrency_safe(&self, args: &Value) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

fn execute<'life0, 'async_trait>( &'life0 self, _args: Value, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionNoteTool: 'async_trait,

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, SessionNoteTool: 'async_trait,

Source§

impl Tool for NotebookEditTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for ReadTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, ReadTool: 'async_trait,

Source§

impl Tool for RequestPermissionsTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for SlashCommandTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, SlashCommandTool: 'async_trait,

Source§

impl Tool for SleepTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for TaskTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for WebFetchTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for WebSearchTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn concurrency_safe(&self) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, WebSearchTool: 'async_trait,

Source§

impl Tool for WorkspaceTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn mutability(&self) -> ToolMutability

Source§

fn call_mutability(&self, args: &Value) -> ToolMutability

Source§

fn call_concurrency_safe(&self, args: &Value) -> bool

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, WorkspaceTool: 'async_trait,

Source§

impl Tool for WriteTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

fn execute_with_context<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: ToolExecutionContext<'life1>, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, WriteTool: 'async_trait,

Implementors§