Skip to main content

Tool

Trait Tool 

Source
pub trait Tool:
    Send
    + Sync
    + 'static {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters(&self) -> Value;
    fn call<'a>(
        &'a self,
        invocation: ToolInvocation,
    ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>;

    // Provided method
    fn read_only(&self) -> bool { ... }
}
Available on crate feature tool-loop only.
Expand description

Something a model may call.

Object-safe, with a boxed future like AgentExecutor. ToolSet holds each as an Arc<dyn Tool>.

Required Methods§

Source

fn name(&self) -> &str

The name the model calls it by. Unique within a ToolSet.

Source

fn description(&self) -> &str

What it does. The model chooses tools by this text, so say when to call it as well as what it returns.

Source

fn parameters(&self) -> Value

A JSON Schema for the arguments, an object schema.

Source

fn call<'a>( &'a self, invocation: ToolInvocation, ) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>

Runs the call.

§Errors

ToolError::Failed to tell the model what went wrong; ToolError::Fatal to end the task.

Provided Methods§

Source

fn read_only(&self) -> bool

Whether a call changes nothing, so running it again is harmless: a lookup, a status query, a search. false unless a tool says so.

Within one run, a call identical to one that already succeeded — same tool, same arguments — is not run again when the tool is not read-only: the model is sent the earlier result, marked as such (ADR 0026). A read-only tool is run each time, so a model can poll it for a change.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§