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) -> Tool { ... }
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§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Get the tool description.
Sourcefn input_schema(&self) -> &str
fn input_schema(&self) -> &str
Get the input schema as JSON string.
Provided Methods§
Sourcefn to_definition(&self) -> ToolDefinition
fn to_definition(&self) -> ToolDefinition
Convert to LLM tool definition.
Sourcefn to_llm_tool(&self) -> Tool
fn to_llm_tool(&self) -> Tool
Convert to LLMTool for provider APIs.
Sourcefn display_config(&self) -> DisplayConfig
fn display_config(&self) -> DisplayConfig
Get display configuration for UI rendering.
Sourcefn compact_summary(
&self,
_input: &HashMap<String, Value>,
_result: &str,
) -> String
fn compact_summary( &self, _input: &HashMap<String, Value>, _result: &str, ) -> String
Generate compact summary for context compaction.
Sourcefn required_permissions(
&self,
_context: &ToolContext,
_input: &HashMap<String, Value>,
) -> Option<Vec<PermissionRequest>>
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 IDsinput- The input parameters for this tool call
§Returns
None- No permissions required (default)Some(Vec<PermissionRequest>)- List of permissions to request
Sourcefn handles_own_permissions(&self) -> bool
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)
Sourcefn cleanup_session(
&self,
_session_id: i64,
) -> Pin<Box<dyn Future<Output = ()> + Send + '_>>
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)