pub trait Tool: Send + Sync {
// Required methods
fn definition(&self) -> ToolDef;
fn approval(&self, args: &str) -> ApprovalRequirement;
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 str,
ctx: &'life2 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn approval_with_context(
&self,
args: &str,
_ctx: &ToolContext,
) -> ApprovalRequirement { ... }
fn validate_args(&self, _args: &str) -> Result<(), String> { ... }
}Required Methods§
fn definition(&self) -> ToolDef
fn approval(&self, args: &str) -> ApprovalRequirement
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 str,
ctx: &'life2 ToolContext,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Provided Methods§
fn approval_with_context( &self, args: &str, _ctx: &ToolContext, ) -> ApprovalRequirement
Sourcefn validate_args(&self, _args: &str) -> Result<(), String>
fn validate_args(&self, _args: &str) -> Result<(), String>
Pre-flight syntactic check on raw tool-call arguments. The runner calls this before approval and before execute, so a parse failure short-circuits to a tool-result error and the model receives a structured retry hint without bothering the user.
Default impl: Ok(()). Tools with strict required-field schemas
(write_file / edit_file / search_replace) override to surface the
serde error early. Implementations should be cheap (parse only,
no I/O) — the runner re-parses inside execute() for actual use.
Trigger context (2026-05-02 datalog evidence): provider-side
stream truncation can deliver [RAW ARGS: {] or
[RAW ARGS: {"file_path":"..."] (closing-bracket wrong, content
missing). The previous flow let those reach approval_with_context
where the tool’s own fail-closed branch returned
RequireApproval("Could not parse … for safety check.") and the
user saw an approval prompt for an obviously-broken call. Pressing
Allow then died on the same parse in execute(). Validating up
front eliminates the user-visible round-trip entirely.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".