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 { ... }
}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§
Sourcefn description(&self) -> &str
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.
Sourcefn parameters(&self) -> Value
fn parameters(&self) -> Value
A JSON Schema for the arguments, an object schema.
Sourcefn call<'a>(
&'a self,
invocation: ToolInvocation,
) -> Pin<Box<dyn Future<Output = Result<String, ToolError>> + Send + 'a>>
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§
Sourcefn read_only(&self) -> bool
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".