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§
Sourcefn declaration(&self) -> &ToolDeclaration
fn declaration(&self) -> &ToolDeclaration
Name, description and argument schema as sent to the model.
Sourcefn execute(
&self,
call_id: String,
args: Value,
cancel: CancellationToken,
updates: UpdateSink,
) -> BoxFuture<'_, Result<ToolResult, String>>
fn execute( &self, call_id: String, args: Value, cancel: CancellationToken, updates: UpdateSink, ) -> BoxFuture<'_, Result<ToolResult, String>>
Runs the tool with validated arguments.
Provided Methods§
Sourcefn execution_mode(&self) -> ExecutionMode
fn execution_mode(&self) -> ExecutionMode
See ExecutionMode.
Sourcefn output_schema(&self) -> Option<&Value>
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).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".