pub struct Tool { /* private fields */ }Expand description
A callable tool that can be registered on a client or request.
Use Tool::new to start building, chain .description() and .handler(),
where .handler() is fallible and validates the schema at build time.
§Example
use rai_sdk::{JsonSchema, Tool};
use serde::Deserialize;
#[derive(Deserialize, JsonSchema)]
#[schemars(crate = "rai_sdk::schemars")]
struct GetUserInfo {
user_id: String,
}
let _tool = Tool::new("get_user_info")
.description("Load a user's profile")
.handler(|input: GetUserInfo, _ctx: rai_sdk::ToolContext| async move {
Ok(serde_json::json!({ "user_id": input.user_id, "email": "user@example.com" }))
})?;Implementations§
Source§impl Tool
impl Tool
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Describe when the model should use this tool.
Sourcepub fn json_schema(self, input_schema: Value) -> Self
pub fn json_schema(self, input_schema: Value) -> Self
Override the inferred input schema with a custom JSON Schema.
Sourcepub fn handler<Args, Output, F, Fut>(self, handler: F) -> Result<Self>where
Args: DeserializeOwned + JsonSchema + Send + 'static,
Output: Serialize + Send + 'static,
F: Fn(Args, ToolContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Output>> + Send + 'static,
pub fn handler<Args, Output, F, Fut>(self, handler: F) -> Result<Self>where
Args: DeserializeOwned + JsonSchema + Send + 'static,
Output: Serialize + Send + 'static,
F: Fn(Args, ToolContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Output>> + Send + 'static,
Attach an async handler and infer the input schema from Args.
This is fallible — the schema is validated at build time and an error is returned if it is invalid.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Tool
impl !UnwindSafe for Tool
impl Freeze for Tool
impl Send for Tool
impl Sync for Tool
impl Unpin for Tool
impl UnsafeUnpin for Tool
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