pub trait ToolDefinition {
type Input: DeserializeOwned + JsonSchema + Send + Sync + 'static;
type Output: Serialize + Send + Sync + 'static;
// Required methods
fn name(&self) -> String;
fn description(&self) -> String;
// Provided method
fn schema(&self) -> Result<Value> { ... }
}Expand description
Core trait for defining tools with associated input and output types
This trait provides a more flexible and type-safe way to define tools compared
to the original Tool trait. It uses associated types to specify the input and output
types for a tool, allowing for better compile-time type checking.
§Type Parameters
Input- The type of input that this tool accepts, must implementDeserializeOwnedandJsonSchemaOutput- The type of output that this tool produces, must implementSerialize
§Examples
use language_barrier_core::ToolDefinition;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, JsonSchema)]
struct WeatherRequest {
location: String,
units: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
struct WeatherResponse {
temperature: f64,
condition: String,
location: String,
units: String,
}
struct WeatherTool;
impl ToolDefinition for WeatherTool {
type Input = WeatherRequest;
type Output = WeatherResponse;
fn name(&self) -> String {
"get_weather".to_string()
}
fn description(&self) -> String {
"Get current weather for a location".to_string()
}
}Required Associated Types§
Sourcetype Input: DeserializeOwned + JsonSchema + Send + Sync + 'static
type Input: DeserializeOwned + JsonSchema + Send + Sync + 'static
The input type that this tool accepts
Required Methods§
Sourcefn description(&self) -> String
fn description(&self) -> String
Returns the description of the tool