Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn declaration(&self) -> &ToolDeclaration;
    fn execute(
        &self,
        call_id: String,
        args: Value,
        cancel: CancellationToken,
        updates: UpdateSink,
    ) -> BoxFuture<'_, Result<ToolResult, String>>;

    // Provided methods
    fn label(&self) -> &str { ... }
    fn execution_mode(&self) -> ExecutionMode { ... }
    fn output_schema(&self) -> Option<&Value> { ... }
    fn prepare_arguments(
        &self,
        arguments: Map<String, Value>,
    ) -> Map<String, Value> { ... }
}
Expand description

A tool: a declaration for the model and an implementation.

execute returns Err with a message for failures, and the loop turns it into an error result. Cancellation is cooperative through cancel.

Required Methods§

Source

fn declaration(&self) -> &ToolDeclaration

Name, description and argument schema as sent to the model.

Source

fn execute( &self, call_id: String, args: Value, cancel: CancellationToken, updates: UpdateSink, ) -> BoxFuture<'_, Result<ToolResult, String>>

Runs the tool with validated arguments.

Provided Methods§

Source

fn label(&self) -> &str

Human-readable name for the UI.

Source

fn execution_mode(&self) -> ExecutionMode

Source

fn output_schema(&self) -> Option<&Value>

JSON Schema of the value the tool returns as structuredContent, for tools whose results scripts consume (pi’s outputSchema).

Source

fn prepare_arguments(&self, arguments: Map<String, Value>) -> Map<String, Value>

Rewrites raw arguments before validation, for compatibility with older argument shapes.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§