Skip to main content

Tool

Struct Tool 

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

Implementations§

Source§

impl Tool

Source

pub fn into_builder(self) -> ToolBuilder<JsonValue>

Reopens this tool for configuration, preserving its definition and callbacks.

The builder’s execute closure receives JSON input; the existing input schema and executor are retained until explicitly replaced.

§Examples
use ferrin_tool::{Tool, ToolError};
use ferrin_spec::JsonObject;
let tool = Tool::provider_defined("provider.search", JsonObject::new()).build();
let executable = tool.into_builder()
    .execute(|input: serde_json::Value, _| async move {
        Ok::<_, ToolError>(input)
    })
    .build();
assert!(executable.is_executable());
Source

pub fn function<I: DeserializeOwned + JsonSchema + 'static>() -> ToolBuilder<I>

A function tool whose input schema is derived from I (draft-07, additionalProperties: false on objects).

Source

pub fn function_with_schema( input_schema: Schema<JsonValue>, ) -> ToolBuilder<JsonValue>

A function tool with an explicit JSON schema; the execute closure receives the raw JSON input.

Source

pub fn dynamic(input_schema: Schema<JsonValue>) -> ToolBuilder<JsonValue>

A dynamic tool (runtime-defined schema, untyped input and output).

Source

pub fn provider_defined( id: impl Into<String>, args: JsonObject, ) -> ToolBuilder<JsonValue>

A provider-defined tool executed by the application. The input schema defaults to “any”; provider crates set the real one.

Source

pub fn provider_executed( id: impl Into<String>, args: JsonObject, ) -> ToolBuilder<JsonValue>

A provider-executed tool.

Source§

impl Tool

Source

pub fn kind(&self) -> &ToolKind

The kind.

Source

pub fn description(&self) -> Option<&Description>

The description declaration.

Source

pub fn title(&self) -> Option<&str>

The title.

Source

pub fn input_schema(&self) -> &Schema<JsonValue>

The input schema (erased to JSON).

Source

pub fn output_schema(&self) -> Option<&Schema<JsonValue>>

The output schema, if declared.

Source

pub fn context_schema(&self) -> Option<&Schema<JsonValue>>

The context schema, if declared.

Source

pub fn executor(&self) -> Option<&Arc<dyn ToolExecute>>

The executor, if the tool is executed by the application.

Source

pub fn is_executable(&self) -> bool

Returns true when the tool has an executor.

Source

pub fn needs_approval(&self) -> &NeedsApproval

The approval declaration.

Source

pub fn strict(&self) -> Option<bool>

Strict-mode request.

Source

pub fn input_examples(&self) -> &[JsonObject]

Example inputs.

Source

pub fn metadata(&self) -> Option<&JsonObject>

Metadata propagated to tool calls (not sent to the model).

Source

pub fn provider_options(&self) -> Option<&ProviderOptions>

Provider options sent with the tool definition.

Source

pub fn hooks(&self) -> &ToolHooks

Input lifecycle hooks.

Source

pub fn to_model_output(&self) -> Option<&ToModelOutputFn>

Custom model-output conversion.

Source

pub fn caller_definition(&self) -> Option<&ToolCallerDefinition>

Caller definition, when this tool can call other tools.

Source

pub fn with_provider_options( self, provider_options: Option<ProviderOptions>, ) -> Self

Returns a copy with different provider options.

Source

pub async fn resolve_description( &self, ctx: DescriptionContext, ) -> Option<String>

Resolves the description for a call (None when the tool has none).

Source

pub fn definition( &self, name: ToolName, description: Option<String>, ) -> ToolDefinition

Builds the provider-facing definition under name.

Source

pub fn validate_input( &self, name: &ToolName, input: JsonValue, ) -> Result<JsonValue, TypeValidationError>

Validates an input against the input schema.

§Errors

Returns the validation error with field: "tool input" and the tool name as entity.

Source

pub fn validate_context( &self, name: &ToolName, context: Option<JsonValue>, ) -> Result<Option<JsonValue>, TypeValidationError>

Validates the selected tool context, preserving it when no schema is set.

§Errors

Returns the validation error with field: "tool context".

Source

pub fn validate_named_context( &self, name: &ToolName, contexts: Option<&JsonValue>, ) -> Result<Option<JsonValue>, TypeValidationError>

Selects this tool’s entry from a named context map and validates it.

The map is keyed by the registered tool name. Missing entries remain absent without a schema and are validated as JSON null with a schema.

§Errors

Returns a validation error for a non-object context map or when the selected entry does not satisfy this tool’s context schema.

Source

pub fn execute( &self, input: JsonValue, ctx: ToolContext, ) -> Option<ToolOutputStream>

Starts an execution; None when the tool has no executor.

Trait Implementations§

Source§

impl Clone for Tool

Source§

fn clone(&self) -> Tool

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tool

Source§

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

Formats the value using the given formatter. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.