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(&self) -> Value;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        params: Value,
        ctx: ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<String, RuntimeError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn execute_rich<'life0, 'async_trait>(
        &'life0 self,
        params: Value,
        ctx: ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, RuntimeError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
    fn extension_id(&self) -> Option<&str> { ... }
    fn origin(&self) -> ToolOrigin { ... }
    fn effect(&self) -> ToolEffect { ... }
    fn runs_independently(&self) -> bool { ... }
    fn concurrency_key(
        &self,
        _validated_input: &Value,
    ) -> Option<ConcurrencyKey> { ... }
}
Expand description

The core trait for all tools. Implement this to add a new tool.

Required Methods§

Source

fn name(&self) -> &str

Tool name as it appears in the API (e.g. “bash”, “read”).

Source

fn description(&self) -> &str

Human-readable description sent to the model.

Source

fn parameters(&self) -> Value

JSON Schema for the tool’s parameters.

Source

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

Execute the tool with the given parameters.

Provided Methods§

Source

fn execute_rich<'life0, 'async_trait>( &'life0 self, params: Value, ctx: ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, RuntimeError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Structured variant of Tool::execute. DEFAULTED — existing tools keep returning String via execute and never see this. Tools that need to place non-text content blocks (images) into the model history override this and make execute delegate to it.

RECURSION TRAP: the default delegates to execute. If you make execute delegate here (as ReadTool does) you MUST override this method too, or the pair recurses until the stack blows.

Source

fn extension_id(&self) -> Option<&str>

Owning extension id for tools registered by an extension. Built-in tools return None.

Source

fn origin(&self) -> ToolOrigin

Runtime-origin identity used for catalog provenance. Conservative by default: tools that declare nothing are Unknown (fail-closed source trust), and tools that declare an owning extension classify as extension-provided. Built-in implementations override this explicitly.

Source

fn effect(&self) -> ToolEffect

Conservative effect class (Task 24, spec §8.2). The default keeps unknown/dynamic tools NonIdempotent — serialized execution; implementations opt IN to weaker classes explicitly.

Source

fn runs_independently(&self) -> bool

Each call is its own independent actor (a subagent): sibling calls in one batch each get their own scheduler lane and run concurrently, instead of joining the shared serial lane that NonIdempotent tools use. Scheduling only — the effect class, and with it the rule that an interrupted call is never re-run automatically, is unchanged.

Source

fn concurrency_key(&self, _validated_input: &Value) -> Option<ConcurrencyKey>

Key resolution derived from validated input. Serialize explicitly fails closed into the global mutation lane; None is the conservative default for tools with no key support.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§