pub trait Tool:
Sized
+ WasmCompatSend
+ WasmCompatSync {
type Args: for<'de> Deserialize<'de> + WasmCompatSend + WasmCompatSync;
type Output: IntoToolOutput;
type Error: Error + WasmCompatSend + WasmCompatSync + 'static;
const NAME: &'static str;
// Required methods
fn description(&self) -> String;
fn parameters(&self) -> Value;
fn call(
&self,
context: &mut ToolContext,
args: Self::Args,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend;
// Provided method
fn map_error(&self, error: Self::Error) -> ToolExecutionError { ... }
}Expand description
A typed LLM tool.
Tool authors provide metadata and exactly one execution method. Runtime
context and host-only result metadata share the ToolContext path. Rig’s
object-safe dispatch boundary is private; use DynamicTool when the tool
name or callback is only known at runtime.
Required Associated Constants§
Required Associated Types§
Sourcetype Args: for<'de> Deserialize<'de> + WasmCompatSend + WasmCompatSync
type Args: for<'de> Deserialize<'de> + WasmCompatSend + WasmCompatSync
Typed JSON arguments.
Sourcetype Output: IntoToolOutput
type Output: IntoToolOutput
Output convertible into Rig’s canonical model presentation.
Every owned serializable value implements IntoToolOutput
automatically. ToolResultContent
and OneOrMany preserve rich content when returned
directly; use ToolOutput when constructing the presentation
explicitly.
Sourcetype Error: Error + WasmCompatSend + WasmCompatSync + 'static
type Error: Error + WasmCompatSend + WasmCompatSync + 'static
Typed error returned by direct calls to this tool.
Rig normalizes this error into ToolExecutionError only at the erased
dispatch boundary. This keeps ordinary ? propagation and typed unit
tests available to tool authors without creating a second runtime error
representation.
Required Methods§
Sourcefn description(&self) -> String
fn description(&self) -> String
Model-facing description.
Sourcefn parameters(&self) -> Value
fn parameters(&self) -> Value
JSON Schema for arguments.
Sourcefn call(
&self,
context: &mut ToolContext,
args: Self::Args,
) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend
fn call( &self, context: &mut ToolContext, args: Self::Args, ) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend
Execute the tool.
Provided Methods§
Sourcefn map_error(&self, error: Self::Error) -> ToolExecutionError
fn map_error(&self, error: Self::Error) -> ToolExecutionError
Normalize a typed author-facing error for runtime policy and telemetry.
The default preserves the concrete source and classifies it as
crate::tool::ToolErrorKind::Other. Override this method when the domain error can
provide a more precise kind, retryability policy, or safe model output.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
Source§impl Tool for MockAddTool
Available on crate feature test-utils only.
impl Tool for MockAddTool
test-utils only.Source§impl Tool for MockBarrierTool
Available on crate feature test-utils only.
impl Tool for MockBarrierTool
test-utils only.Source§impl Tool for MockContextProbeTool
Available on crate feature test-utils only.
impl Tool for MockContextProbeTool
test-utils only.Source§impl Tool for MockControlledTool
Available on crate feature test-utils only.
impl Tool for MockControlledTool
test-utils only.Source§impl Tool for MockDeniedTool
Available on crate feature test-utils only.
impl Tool for MockDeniedTool
test-utils only.Source§impl Tool for MockExampleTool
Available on crate feature test-utils only.
impl Tool for MockExampleTool
test-utils only.Source§impl Tool for MockFailingTool
Available on crate feature test-utils only.
impl Tool for MockFailingTool
test-utils only.Source§impl Tool for MockHandledFailureTool
Available on crate feature test-utils only.
impl Tool for MockHandledFailureTool
test-utils only.Source§impl Tool for MockImageGeneratorTool
Available on crate feature test-utils only.
impl Tool for MockImageGeneratorTool
test-utils only.Source§impl Tool for MockImageOutputTool
Available on crate feature test-utils only.
impl Tool for MockImageOutputTool
test-utils only.Source§impl Tool for MockMetadataTool
Available on crate feature test-utils only.
impl Tool for MockMetadataTool
test-utils only.Source§impl Tool for MockObjectOutputTool
Available on crate feature test-utils only.
impl Tool for MockObjectOutputTool
test-utils only.Source§impl Tool for MockStringOutputTool
Available on crate feature test-utils only.
impl Tool for MockStringOutputTool
test-utils only.Source§impl Tool for MockSubtractTool
Available on crate feature test-utils only.
impl Tool for MockSubtractTool
test-utils only.