Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn spec(&self) -> ToolSpec;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        arguments: Value,
    ) -> Pin<Box<dyn Future<Output = Result<String>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided methods
    fn side_effect_class(&self) -> ToolSideEffect { ... }
    fn is_readonly(&self) -> bool { ... }
    fn is_readonly_for_args(&self, _arguments: &Value) -> bool { ... }
}

Required Methods§

Source

fn spec(&self) -> ToolSpec

Source

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

Provided Methods§

Source

fn side_effect_class(&self) -> ToolSideEffect

Classify this tool’s observable side-effects. Default is the most conservative value (External) so any unannotated tool is treated as risky on resume. Override to ReadOnly or Mutating for built-in tools; MCP tools derive this from their annotations.

Source

fn is_readonly(&self) -> bool

Convenience: a tool is read-only iff it classifies as ReadOnly. Used by the parallel-dispatch path in agent.rs. Override only if you have an unusual reason (you almost never should — override side_effect_class instead and let this default through).

Source

fn is_readonly_for_args(&self, _arguments: &Value) -> bool

Like is_readonly but can inspect the call-time arguments.

Override this when read-only-ness depends on parameters (e.g. sub_agent with subagent_type: "explore" behaves as read-only while "general_purpose" is not). The default delegates to is_readonly().

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§