Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn definition(&self) -> ToolDefinition;
    fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ToolCallContext,
        control: &'life2 CallControl,
        store: Option<&'life3 dyn ArtifactStore>,
    ) -> Pin<Box<dyn Future<Output = ToolResultPayload> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait;

    // Provided method
    fn hints(&self) -> ToolHints { ... }
}
Expand description

The tool port: one callable tool the model can invoke. Implementations live outside the kernel; the driver’s executor dispatches them. A tool returns only its recorded result. Handling unknown outcomes and retaining output belong to the execution consumer, not tool declarations.

§Requirements on execute

An executor may poll every call of one batch on a single task, with nothing spawned. An implementation therefore:

  • must not block the thread. Blocking or CPU-heavy work runs on a blocking thread (for example tokio::task::spawn_blocking) and the tool awaits it;
  • must return promptly once its CallControl is cancelled or past its deadline.

For a tool that meets both, a stop takes effect at its next yield point. A tool that holds the thread also holds its sibling calls and the executor’s own stop and timeout checks, so nothing is guaranteed for it: not cancellation, not the deadline, not a per-call timeout.

Calls of one batch are concurrent, not parallel, and their number is not bounded. A tool that needs a limit shares a semaphore across its calls.

Required Methods§

Source

fn definition(&self) -> ToolDefinition

The model-facing ToolDefinition for this tool.

Source

fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ctx: &'life1 ToolCallContext, control: &'life2 CallControl, store: Option<&'life3 dyn ArtifactStore>, ) -> Pin<Box<dyn Future<Output = ToolResultPayload> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Runs one call under the call’s CallControl, returning the recorded result. store is the host’s ArtifactStore when one is configured: a tool that produces media or oversized output persists the bytes there and returns a reference; a tool that does not need storage ignores it.

Provided Methods§

Source

fn hints(&self) -> ToolHints

What this tool declares about its effects. An executor reads it when it binds the tool, next to Tool::definition, and shows it to tool processors. The default declares nothing.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§