Skip to main content

FunctionTool

Struct FunctionTool 

Source
pub struct FunctionTool { /* private fields */ }
Expand description

A closure-based tool.

Implementations§

Source§

impl FunctionTool

Source

pub fn new<F, Fut>( name: impl Into<String>, description: impl Into<String>, parameters_schema: Value, handler: F, ) -> Self
where F: Fn(Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = ToolResult<Value>> + Send + 'static,

Creates a new function-based tool.

The handler is expected to return a JSON Value; the implementation wraps it in a ToolOutput.

Source

pub fn read_only(self) -> Self

Marks the tool as read-only.

Source

pub fn concurrency_safe(self) -> Self

Marks the tool as safe for concurrent execution.

Source

pub fn long_running(self) -> Self

Marks the tool as long-running.

Source

pub fn side_effects(self, effects: SideEffects) -> Self

Sets the side effects for this tool.

Source

pub fn requires_approval(self, reason: impl Into<String>) -> Self

Marks the tool as requiring human approval.

Trait Implementations§

Source§

impl Debug for FunctionTool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Tool for FunctionTool

Source§

fn name(&self) -> &str

Returns the tool’s name (visible to the model).
Source§

fn description(&self) -> &str

Returns a human-readable description of the tool.
Source§

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,

Executes the tool with the given arguments.
Source§

fn is_read_only(&self) -> bool

Returns true if the tool is read-only (no side effects).
Source§

fn is_concurrency_safe(&self) -> bool

Returns true if the tool is safe to run concurrently.
Source§

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

Returns the side effects the tool may produce.
Source§

fn requires_approval(&self) -> bool

Returns true if the tool requires human approval before execution.
Source§

fn approval_reason(&self) -> Option<String>

Returns the reason approval is needed, if applicable.
Source§

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,

Executes the tool with the given ToolContext and arguments. Read more
Source§

fn required_scopes(&self) -> &[&str]

Returns the scopes required to use this tool.
Source§

fn to_spec(&self) -> ToolSpec

Produces a ToolSpec for this tool.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.