pub struct TypedTool<T: DeserializeOwned + JsonSchema + Send + Sync + 'static> { /* private fields */ }Expand description
Type-safe function tool with auto-generated JSON Schema.
Unlike super::SimpleTool which takes raw serde_json::Value arguments and
requires a manually written schema, TypedTool auto-generates the JSON
Schema from a struct that derives [schemars::JsonSchema] and deserializes
the arguments into that struct before calling the handler.
§Example
ⓘ
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
struct WeatherArgs {
/// The city to get weather for
city: String,
}
let tool = TypedTool::new::<WeatherArgs>(
"get_weather",
"Get current weather for a city",
|args: WeatherArgs| async move {
Ok(serde_json::json!({ "temp": 22, "city": args.city }))
},
);Implementations§
Source§impl<T: DeserializeOwned + JsonSchema + Send + Sync + 'static> TypedTool<T>
impl<T: DeserializeOwned + JsonSchema + Send + Sync + 'static> TypedTool<T>
Trait Implementations§
Source§impl<T: DeserializeOwned + JsonSchema + Send + Sync + 'static> ToolFunction for TypedTool<T>
impl<T: DeserializeOwned + JsonSchema + Send + Sync + 'static> ToolFunction for TypedTool<T>
Source§fn description(&self) -> &str
fn description(&self) -> &str
Human-readable description of what this tool does.
Source§fn parameters(&self) -> Option<Value>
fn parameters(&self) -> Option<Value>
JSON Schema for the tool’s input parameters, or
None if parameterless.Auto Trait Implementations§
impl<T> Freeze for TypedTool<T>
impl<T> !RefUnwindSafe for TypedTool<T>
impl<T> Send for TypedTool<T>
impl<T> Sync for TypedTool<T>
impl<T> Unpin for TypedTool<T>where
T: Unpin,
impl<T> !UnwindSafe for TypedTool<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more