Skip to main content

FunctionTool

Struct FunctionTool 

Source
pub struct FunctionTool<Input, Output, Handler> { /* private fields */ }
Expand description

A typed asynchronous Rust function exposed through the canonical Tool boundary.

Implementations§

Source§

impl<Input, Output, Handler> FunctionTool<Input, Output, Handler>
where Input: JsonSchema, Output: JsonSchema,

Source

pub fn new( name: impl Into<String>, description: impl Into<String>, handler: Handler, ) -> Self

Creates a typed Tool with generated input and output JSON Schemas.

The default effect is EffectClass::Pure and the default risk is RiskLevel::Low. Callers must explicitly override these values for functions that read or modify external state.

Source§

impl<Input, Handler> FunctionTool<Input, ToolOutput, Handler>
where Input: JsonSchema,

Source

pub fn new_rich( name: impl Into<String>, description: impl Into<String>, handler: Handler, ) -> Self

Creates a typed Tool whose handler returns canonical rich content.

Unlike Self::new, this constructor preserves the returned ToolOutput instead of serializing it into JSON text. The default output schema is permissive because rich presentation content and optional structured content are validated by the canonical Tool boundary rather than one generated Rust output type.

Source§

impl<Input, Output, Handler> FunctionTool<Input, Output, Handler>

Source

pub const fn capability_id(self, id: CapabilityId) -> Self

Replaces the stable capability identity.

Source

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

Sets the semantic Tool contract version.

Source

pub const fn effect(self, effect: EffectClass) -> Self

Declares external-effect behavior.

Source

pub const fn risk(self, risk: RiskLevel) -> Self

Declares policy risk.

Source

pub fn metadata(self, key: impl Into<String>, value: Value) -> Self

Adds host-only namespaced metadata.

Source

pub fn output_schema(self, schema: Value) -> Self

Replaces the successful output schema.

This is primarily useful for rich Tools that attach typed structured_content alongside media. The registry compiles and enforces the schema before exposing a successful result to an Agent.

Trait Implementations§

Source§

impl<Input, Output, Handler> Debug for FunctionTool<Input, Output, Handler>

Source§

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

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

impl<Input, Output, Handler, HandlerFuture> Tool for FunctionTool<Input, Output, Handler>
where Input: DeserializeOwned + JsonSchema + Send + 'static, Output: JsonSchema + Serialize + Send + 'static, Handler: Fn(Input, ToolContext) -> HandlerFuture + Send + Sync, HandlerFuture: Future<Output = Result<Output, ToolError>> + Send + 'static,

Source§

fn descriptor(&self) -> &ToolDescriptor

Returns the tool’s immutable semantic contract.
Source§

fn invoke( &self, input: Value, context: ToolContext, ) -> ToolFuture<'_, Result<ToolOutput, ToolError>>

Executes one invocation.
Source§

impl<Input, Handler, HandlerFuture> Tool for FunctionTool<Input, ToolOutput, Handler>
where Input: DeserializeOwned + JsonSchema + Send + 'static, Handler: Fn(Input, ToolContext) -> HandlerFuture + Send + Sync, HandlerFuture: Future<Output = Result<ToolOutput, ToolError>> + Send + 'static,

Source§

fn descriptor(&self) -> &ToolDescriptor

Returns the tool’s immutable semantic contract.
Source§

fn invoke( &self, input: Value, context: ToolContext, ) -> ToolFuture<'_, Result<ToolOutput, ToolError>>

Executes one invocation.

Auto Trait Implementations§

§

impl<Input, Output, Handler> Freeze for FunctionTool<Input, Output, Handler>
where Handler: Freeze,

§

impl<Input, Output, Handler> RefUnwindSafe for FunctionTool<Input, Output, Handler>
where Handler: RefUnwindSafe,

§

impl<Input, Output, Handler> Send for FunctionTool<Input, Output, Handler>
where Handler: Send,

§

impl<Input, Output, Handler> Sync for FunctionTool<Input, Output, Handler>
where Handler: Sync,

§

impl<Input, Output, Handler> Unpin for FunctionTool<Input, Output, Handler>
where Handler: Unpin,

§

impl<Input, Output, Handler> UnsafeUnpin for FunctionTool<Input, Output, Handler>
where Handler: UnsafeUnpin,

§

impl<Input, Output, Handler> UnwindSafe for FunctionTool<Input, Output, Handler>
where Handler: UnwindSafe,

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> 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, 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.