pub trait Tool: WasmCompatSend + WasmCompatSync {
type Args: DeserializeOwned + JsonSchema + WasmCompatSend;
type Output: Serialize;
type Error: Error + WasmCompatSend + 'static;
const NAME: &'static str;
// Required methods
fn definition(&self) -> ToolDefinition;
fn call(
&self,
args: Self::Args,
ctx: &ToolContext,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend;
}Expand description
Strongly-typed tool trait. Implement this for your tools.
The blanket impl of ToolDyn handles JSON deserialization/serialization
so you work with concrete Rust types.
§Example
use neuron_types::*;
use serde::Deserialize;
#[derive(Debug, Deserialize, schemars::JsonSchema)]
struct MyArgs { query: String }
struct MyTool;
impl Tool for MyTool {
const NAME: &'static str = "my_tool";
type Args = MyArgs;
type Output = String;
type Error = std::io::Error;
fn definition(&self) -> ToolDefinition { todo!() }
fn call(&self, args: MyArgs, ctx: &ToolContext)
-> impl Future<Output = Result<String, std::io::Error>> + Send
{ async { Ok(args.query) } }
}Required Associated Constants§
Required Associated Types§
Sourcetype Args: DeserializeOwned + JsonSchema + WasmCompatSend
type Args: DeserializeOwned + JsonSchema + WasmCompatSend
The deserialized input type.
Sourcetype Error: Error + WasmCompatSend + 'static
type Error: Error + WasmCompatSend + 'static
The tool-specific error type.
Required Methods§
Sourcefn definition(&self) -> ToolDefinition
fn definition(&self) -> ToolDefinition
Returns the tool definition (name, description, schema).
Sourcefn call(
&self,
args: Self::Args,
ctx: &ToolContext,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend
fn call( &self, args: Self::Args, ctx: &ToolContext, ) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend
Execute the tool with typed arguments.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.