Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn spec(&self) -> &ToolSpec;
    fn call<'life0, 'life1, 'async_trait>(
        &'life0 self,
        args: Value,
        ctx: &'life1 ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;

    // Provided method
    fn uses_network(&self) -> bool { ... }
}
Expand description

A capability an agent can call: a spec the model sees and an async call. Object safe, so registries hold Arc<dyn Tool>. Arguments arrive as JSON already checked against spec().schema when called through a registry.

Required Methods§

Source

fn spec(&self) -> &ToolSpec

Returns the name, description and argument schema the model sees.

Source

fn call<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: &'life1 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Runs the tool with JSON args and the per-call ctx. Returns the model-facing output or a ToolError.

Provided Methods§

Source

fn uses_network(&self) -> bool

Reports whether a call sends a request over the network, as web_fetch, web_search, HTTP and hosted tools do. A private agent refuses such a tool at build. Default false: override it when true.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl Tool for FnTool

Source§

fn spec(&self) -> &ToolSpec

Source§

fn call<'life0, 'life1, 'async_trait>( &'life0 self, args: Value, ctx: &'life1 ToolContext, ) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, FnTool: 'async_trait,

Implementors§

Source§

impl<A, F, Fut> Tool for TypedTool<A, F>
where A: DeserializeOwned + JsonSchema + Send + 'static, F: Fn(A, ToolContext) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<ToolOutput, ToolError>> + Send + 'static,