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 execute(
        &self,
        input: &Value,
    ) -> impl Future<Output = Result<ToolOutput>> + Send;

    // Provided method
    fn retry_policy(&self) -> Option<ToolRetryPolicy> { ... }
}
Expand description

Trait for tools the agent can invoke. Tools must have unique names and declare a JSON Schema for parameters.

Required Methods§

Source

fn name(&self) -> &str

Unique identifier for the tool. Used by the model when requesting a call.

Source

fn description(&self) -> &str

Human-readable description. The model uses this to decide when to call the tool.

Source

fn parameters_schema(&self) -> Value

JSON Schema for the tool’s parameters. Validates and guides the model’s argument generation.

Source

fn execute( &self, input: &Value, ) -> impl Future<Output = Result<ToolOutput>> + Send

Executes the tool with the given arguments. Arguments are validated by the model; implementors may still validate.

Provided Methods§

Source

fn retry_policy(&self) -> Option<ToolRetryPolicy>

Per-tool retry policy. If Some, overrides the agent-level retry policy for this tool. Return None to use the agent’s default.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§