Skip to main content

Executable

Trait Executable 

Source
pub trait Executable: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn input_schema(&self) -> &str;
    fn tool_type(&self) -> ToolType;
    fn execute(
        &self,
        context: ToolContext,
        input: HashMap<String, Value>,
    ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>>;

    // Provided methods
    fn to_definition(&self) -> ToolDefinition { ... }
    fn to_llm_tool(&self) -> LLMTool { ... }
    fn display_config(&self) -> DisplayConfig { ... }
    fn compact_summary(
        &self,
        _input: &HashMap<String, Value>,
        _result: &str,
    ) -> String { ... }
    fn required_permissions(
        &self,
        _context: &ToolContext,
        _input: &HashMap<String, Value>,
    ) -> Option<Vec<PermissionRequest>> { ... }
    fn handles_own_permissions(&self) -> bool { ... }
    fn cleanup_session(
        &self,
        _session_id: i64,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>> { ... }
}
Expand description

Trait for executable tools.

Required Methods§

Source

fn name(&self) -> &str

Get the tool name.

Source

fn description(&self) -> &str

Get the tool description.

Source

fn input_schema(&self) -> &str

Get the input schema as JSON string.

Source

fn tool_type(&self) -> ToolType

Get the tool type.

Source

fn execute( &self, context: ToolContext, input: HashMap<String, Value>, ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send>>

Execute the tool with given input.

Provided Methods§

Source

fn to_definition(&self) -> ToolDefinition

Convert to LLM tool definition.

Source

fn to_llm_tool(&self) -> LLMTool

Convert to LLMTool for provider APIs.

Source

fn display_config(&self) -> DisplayConfig

Get display configuration for UI rendering.

Source

fn compact_summary( &self, _input: &HashMap<String, Value>, _result: &str, ) -> String

Generate compact summary for context compaction.

Source

fn required_permissions( &self, _context: &ToolContext, _input: &HashMap<String, Value>, ) -> Option<Vec<PermissionRequest>>

Return the permissions required to execute this tool with the given input.

This method is called by the batch executor to collect all permission requests from tools before execution. If a tool returns Some(vec![...]), those permissions will be requested from the user before execution.

§Arguments
  • context - The tool context including session and tool use IDs
  • input - The input parameters for this tool call
§Returns
  • None - No permissions required (default)
  • Some(Vec<PermissionRequest>) - List of permissions to request
Source

fn handles_own_permissions(&self) -> bool

Whether this tool handles its own permission flow internally.

Tools that return true will NOT have their permissions checked by the batch executor. Use this for tools that have special permission handling needs, such as:

  • AskForPermissions (explicitly requests permission from user)
  • AskUserQuestions (user interaction, not permission-based)

Default: false (executor handles permissions)

Source

fn cleanup_session( &self, _session_id: i64, ) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>

Cleans up any session-specific state when a session is removed.

Tools that maintain per-session state (e.g., working directories, caches) should implement this to clean up when sessions are destroyed, preventing unbounded memory growth from abandoned sessions.

§Arguments
  • session_id - The session being removed

Default: no-op (no session state to clean up)

Implementors§