pub struct FunctionTool { /* private fields */ }Expand description
Convenience wrapper: turns any async function into a Tool.
§Example
ⓘ
let tool = FunctionTool::new(
"add",
"Add two numbers",
serde_json::json!({
"type": "object",
"properties": {
"a": { "type": "number" },
"b": { "type": "number" }
},
"required": ["a", "b"]
}),
|input| Box::pin(async move {
let a = input["a"].as_f64().unwrap_or(0.0);
let b = input["b"].as_f64().unwrap_or(0.0);
Ok(serde_json::json!(a + b))
}),
);Implementations§
Source§impl FunctionTool
impl FunctionTool
Sourcepub fn new(
name: impl Into<String>,
description: impl Into<String>,
parameters: Value,
func: impl Fn(Value) -> Pin<Box<dyn Future<Output = Result<Value, PeError>> + Send>> + Send + Sync + 'static,
) -> Self
pub fn new( name: impl Into<String>, description: impl Into<String>, parameters: Value, func: impl Fn(Value) -> Pin<Box<dyn Future<Output = Result<Value, PeError>> + Send>> + Send + Sync + 'static, ) -> Self
Create a new function tool.
parameters is the JSON Schema for the tool’s input — passed to the LLM.
Trait Implementations§
Source§impl Debug for FunctionTool
impl Debug for FunctionTool
Source§impl Tool for FunctionTool
impl Tool for FunctionTool
Source§fn name(&self) -> &str
fn name(&self) -> &str
Tool name — must be unique within a
super::ToolRegistry.
Sent to the LLM in the tools list.Source§fn description(&self) -> &str
fn description(&self) -> &str
Human-readable description of what this tool does.
The LLM reads this to decide when to call the tool.
Source§fn schema(&self) -> ToolSchema
fn schema(&self) -> ToolSchema
JSON Schema for this tool’s input parameters.
InjectedState and
InjectedStore parameters MUST be excluded.Source§fn execute(&self, input: Value) -> ToolFuture
fn execute(&self, input: Value) -> ToolFuture
Execute the tool with the given input. Called by
super::ToolNode.Source§fn execute_structured(&self, input: Value) -> ToolResultFuture
fn execute_structured(&self, input: Value) -> ToolResultFuture
Execute with structured result metadata. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for FunctionTool
impl !UnwindSafe for FunctionTool
impl Freeze for FunctionTool
impl Send for FunctionTool
impl Sync for FunctionTool
impl Unpin for FunctionTool
impl UnsafeUnpin for FunctionTool
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