pub struct FnTool { /* private fields */ }Expand description
A tool built from a closure — the quickest way to hand the model a function.
use agentyk_core::{FnTool, ToolOutput};
use serde_json::json;
let add = FnTool::new(
"add",
"Add two numbers.",
json!({
"type": "object",
"properties": {"a": {"type": "number"}, "b": {"type": "number"}},
"required": ["a", "b"]
}),
|args| async move {
let a = args["a"].as_f64().unwrap_or(0.0);
let b = args["b"].as_f64().unwrap_or(0.0);
ToolOutput::text((a + b).to_string())
},
);Implementations§
Trait Implementations§
Source§impl Tool for FnTool
impl Tool for FnTool
Source§fn definition(&self) -> ToolDefinition
fn definition(&self) -> ToolDefinition
What the model is told about this tool.
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_context: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolOutput> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
FnTool: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_context: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolOutput> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
FnTool: 'async_trait,
Run it. Read more
Source§fn policy(&self) -> ToolPolicy
fn policy(&self) -> ToolPolicy
Default: always offered to the model — see
ToolPolicy.Auto Trait Implementations§
impl !RefUnwindSafe for FnTool
impl !UnwindSafe for FnTool
impl Freeze for FnTool
impl Send for FnTool
impl Sync for FnTool
impl Unpin for FnTool
impl UnsafeUnpin for FnTool
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