Struct TypedTool
pub struct TypedTool<T>{ /* 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§
§impl<T> TypedTool<T>
impl<T> TypedTool<T>
Trait Implementations§
§impl<T> ToolFunction for TypedTool<T>
impl<T> ToolFunction for TypedTool<T>
§fn description(&self) -> &str
fn description(&self) -> &str
Human-readable description of what this tool does.
§fn parameters(&self) -> Option<Value>
fn parameters(&self) -> Option<Value>
JSON Schema for the tool’s input parameters, or
None if parameterless.§fn call<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
TypedTool<T>: 'async_trait,
fn call<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
TypedTool<T>: 'async_trait,
Execute the tool with the given arguments and return the result.
§fn requires_confirmation(&self) -> bool
fn requires_confirmation(&self) -> bool
Whether this tool must be confirmed before it runs. Defaults to
false. Read more§fn confirmation_message(&self) -> Option<&str>
fn confirmation_message(&self) -> Option<&str>
Optional hint shown when confirmation is requested.
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