pub trait ToolDyn: WasmCompatSend + WasmCompatSync {
// Required methods
fn name(&self) -> String;
fn description(&self) -> String;
fn parameters(&self) -> Value;
fn call<'a>(
&'a self,
args: String,
) -> WasmBoxedFuture<'a, Result<String, ToolError>>;
// Provided methods
fn call_with_extensions<'a>(
&'a self,
args: String,
_extensions: &'a ToolCallExtensions,
) -> WasmBoxedFuture<'a, Result<String, ToolError>> { ... }
fn call_structured<'a>(
&'a self,
args: String,
extensions: &'a ToolCallExtensions,
) -> WasmBoxedFuture<'a, ToolExecutionResult> { ... }
}Expand description
Wrapper trait to allow for dynamic dispatch of simple tools.
This is the object-safe erased form of Tool: it exposes the same flat
metadata and string-based execution methods for runtime dispatch.
Required Methods§
Sourcefn description(&self) -> String
fn description(&self) -> String
Model-facing description of what the tool does.
Sourcefn parameters(&self) -> Value
fn parameters(&self) -> Value
JSON Schema for the tool arguments.
Provided Methods§
Sourcefn call_with_extensions<'a>(
&'a self,
args: String,
_extensions: &'a ToolCallExtensions,
) -> WasmBoxedFuture<'a, Result<String, ToolError>>
fn call_with_extensions<'a>( &'a self, args: String, _extensions: &'a ToolCallExtensions, ) -> WasmBoxedFuture<'a, Result<String, ToolError>>
Dynamic dispatch variant of tool execution with per-call runtime extensions.
The default ignores the extensions and delegates to ToolDyn::call.
The blanket impl for Tool types overrides this to thread the
extensions through to Tool::call_with_extensions.
Sourcefn call_structured<'a>(
&'a self,
args: String,
extensions: &'a ToolCallExtensions,
) -> WasmBoxedFuture<'a, ToolExecutionResult>
fn call_structured<'a>( &'a self, args: String, extensions: &'a ToolCallExtensions, ) -> WasmBoxedFuture<'a, ToolExecutionResult>
Execute the tool with per-call extensions, returning a structured
ToolExecutionResult (model output + ToolOutcome + result
extensions).
This is the structured dynamic boundary the agent loop drives: the result
flows through to the
StepEvent::ToolResult hook event.
Unlike call it never returns a bare error — a failure is
carried as ToolOutcome::Error inside the result, with the
model-visible message on ToolExecutionResult::model_output.
The default wraps call_with_extensions: an
Ok output becomes a ToolOutcome::Success; a ToolError is
classified (ToolError::JsonError as
ToolFailureKind::InvalidArgs, otherwise ToolFailureKind::Other).
The blanket impl for Tool types overrides this to route through
Tool::call_structured and Tool::classify_error; a manual ToolDyn
impl should override it to emit precise outcomes (e.g. a real timeout).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".