pub struct FunctionTool { /* private fields */ }Expand description
A closure-based tool.
Implementations§
Source§impl FunctionTool
impl FunctionTool
Sourcepub fn new<F, Fut>(
name: impl Into<String>,
description: impl Into<String>,
parameters_schema: Value,
handler: F,
) -> Self
pub fn new<F, Fut>( name: impl Into<String>, description: impl Into<String>, parameters_schema: Value, handler: F, ) -> Self
Creates a new function-based tool.
The handler is expected to return a JSON Value; the
implementation wraps it in a ToolOutput.
Sourcepub fn concurrency_safe(self) -> Self
pub fn concurrency_safe(self) -> Self
Marks the tool as safe for concurrent execution.
Sourcepub fn long_running(self) -> Self
pub fn long_running(self) -> Self
Marks the tool as long-running.
Sourcepub fn side_effects(self, effects: SideEffects) -> Self
pub fn side_effects(self, effects: SideEffects) -> Self
Sets the side effects for this tool.
Sourcepub fn requires_approval(self, reason: impl Into<String>) -> Self
pub fn requires_approval(self, reason: impl Into<String>) -> Self
Marks the tool as requiring human approval.
Trait Implementations§
Source§impl Debug for FunctionTool
impl Debug for FunctionTool
Source§impl Tool for FunctionTool
impl Tool for FunctionTool
Source§fn description(&self) -> &str
fn description(&self) -> &str
Returns a human-readable description of the tool.
Source§fn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
Returns the JSON Schema for the tool’s parameters.
Source§fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult<ToolOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult<ToolOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Executes the tool with the given arguments.
Source§fn is_read_only(&self) -> bool
fn is_read_only(&self) -> bool
Returns
true if the tool is read-only (no side effects).Source§fn is_concurrency_safe(&self) -> bool
fn is_concurrency_safe(&self) -> bool
Returns
true if the tool is safe to run concurrently.Source§fn is_long_running(&self) -> bool
fn is_long_running(&self) -> bool
Returns
true if the tool is expected to run for a long time.Source§fn side_effects(&self) -> SideEffects
fn side_effects(&self) -> SideEffects
Returns the side effects the tool may produce.
Source§fn requires_approval(&self) -> bool
fn requires_approval(&self) -> bool
Returns
true if the tool requires human approval before execution.Source§fn approval_reason(&self) -> Option<String>
fn approval_reason(&self) -> Option<String>
Returns the reason approval is needed, if applicable.
Source§fn response_schema(&self) -> Option<Value>
fn response_schema(&self) -> Option<Value>
Returns the JSON Schema for the tool’s response (if any).
Source§fn execute_with_ctx<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 dyn ToolContext,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult<ToolOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_with_ctx<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 dyn ToolContext,
args: Value,
) -> Pin<Box<dyn Future<Output = ToolResult<ToolOutput>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the tool with the given
ToolContext and arguments. Read moreSource§fn required_scopes(&self) -> &[&str]
fn required_scopes(&self) -> &[&str]
Returns the scopes required to use this tool.
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