pub trait Tool:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn schema(&self) -> Value;
fn invoke<'life0, 'async_trait>(
&'life0 self,
input: Value,
) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided methods
fn definition(&self) -> ToolDefinition { ... }
fn requires_store(&self) -> bool { ... }
fn invoke_with_store<'a>(
&'a self,
input: Value,
_store: &'a (dyn Store + 'static),
) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>
where Self: 'a { ... }
}Expand description
Unified tool trait
All tools must implement this trait to be used with ToolNode.
Note: This trait does not implement Debug as it’s an async trait intended for dynamic dispatch via trait objects.
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Get tool description
Provided Methods§
Sourcefn definition(&self) -> ToolDefinition
fn definition(&self) -> ToolDefinition
Get tool definition
Sourcefn requires_store(&self) -> bool
fn requires_store(&self) -> bool
Check if this tool requires Store access
Tools that need persistent cross-thread storage should return true.
The default implementation returns false.
§Returns
true if the tool requires Store access, false otherwise
Sourcefn invoke_with_store<'a>(
&'a self,
input: Value,
_store: &'a (dyn Store + 'static),
) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>where
Self: 'a,
fn invoke_with_store<'a>(
&'a self,
input: Value,
_store: &'a (dyn Store + 'static),
) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>where
Self: 'a,
Execute the tool with Store access
This method is called instead of invoke() when requires_store() returns true.
The default implementation delegates to invoke(), ignoring the Store parameter.
§Arguments
input- Tool input as JSON value (validated against schema)store- Store for cross-thread persistent data access
§Returns
Tool output as string
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".