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

    // Provided methods
    fn classify(&self, _args: &Value) -> ToolClass { ... }
    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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

The sole execution entry: returns the call’s per-call ToolOutcome (Completed / Running / NeedsHuman), or a ToolError for infrastructure / argument failures (preserved from the former execute).

Every tool is context-aware now — the former execute / execute_with_context split is gone, and ctx is owned so an invoke future can be moved into a detached drive task for latency-adaptive promotion.

Provided Methods§

Source

fn classify(&self, _args: &Value) -> ToolClass

Per-call scheduling + permission-gating class (args-aware). Folds the former mutability/call_mutability/concurrency_safe/ call_concurrency_safe hooks into one value. Defaults to the conservative ToolClass::MUTATING_SERIAL (mutating, serial, not promotable).

Source

fn to_schema(&self) -> ToolSchema

Convert tool to LLM-compatible schema.

Creates a ToolSchema suitable for LLM function calling.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Tool for BashInputTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, BashInputTool: 'async_trait,

Source§

impl Tool for BashOutputTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for BashTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, BashTool: '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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: '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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for GrepTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for JsReplTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, KillShellTool: '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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: '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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, RequestPermissionsTool: 'async_trait,

Source§

impl Tool for SessionNoteTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SessionNoteTool: '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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, SlashCommandTool: 'async_trait,

Source§

impl Tool for SleepTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, TaskTool: 'async_trait,

Source§

impl Tool for UpdateGoalTool

Source§

fn classify(&self, _args: &Value) -> ToolClass

Treated as read-only for approval/scheduling purposes: it touches no filesystem or external state. The durable goal-state mutation happens in the engine post-execution handler (same pattern as session_note).

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, UpdateGoalTool: 'async_trait,

Source§

impl Tool for WebFetchTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, _ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, 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 classify(&self, _args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

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

Source§

impl Tool for WorkspaceTool

Source§

fn name(&self) -> &str

Source§

fn description(&self) -> &str

Source§

fn classify(&self, args: &Value) -> ToolClass

Source§

fn parameters_schema(&self) -> Value

Source§

fn invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: '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 invoke<'life0, 'async_trait>( &'life0 self, args: Value, ctx: ToolCtx, ) -> Pin<Box<dyn Future<Output = Result<ToolOutcome, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, WriteTool: 'async_trait,

Implementors§