Skip to main content

Tool

Trait Tool 

Source
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§

Source

const NAME: &'static str

Unique registration and provider-facing name.

Required Associated Types§

Source

type Args: for<'de> Deserialize<'de> + WasmCompatSend + WasmCompatSync

Typed JSON arguments.

Source

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.

Source

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§

Source

fn description(&self) -> String

Model-facing description.

Source

fn parameters(&self) -> Value

JSON Schema for arguments.

Source

fn call( &self, context: &mut ToolContext, args: Self::Args, ) -> impl Future<Output = Result<Self::Output, Self::Error>> + WasmCompatSend

Execute the tool.

Provided Methods§

Source

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.
Source§

impl Tool for MockBarrierTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "barrier_tool"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockContextProbeTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "context_probe"

Source§

type Error = ToolExecutionError

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockControlledTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "controlled"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = i32

Source§

impl Tool for MockDeniedTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "guarded"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockExampleTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "example_tool"

Source§

type Error = MockToolError

Source§

type Args = ()

Source§

type Output = String

Source§

impl Tool for MockFailingTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "flaky_tool"

Source§

type Error = MockFailure

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockHandledFailureTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "lookup"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockImageGeneratorTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "generate_test_image"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = ToolOutput

Source§

impl Tool for MockImageOutputTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "image_output"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = ToolOutput

Source§

impl Tool for MockMetadataTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "with_meta"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockObjectOutputTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "object_output"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = Value

Source§

impl Tool for MockStringOutputTool

Available on crate feature test-utils only.
Source§

const NAME: &'static str = "string_output"

Source§

type Error = MockToolError

Source§

type Args = Value

Source§

type Output = String

Source§

impl Tool for MockSubtractTool

Available on crate feature test-utils only.
Source§

impl<T> Tool for T
where T: PortableTool,

Source§

const NAME: &'static str = <T as rig_core::tool::PortableTool>::NAME

Source§

type Args = <T as PortableTool>::Args

Source§

type Output = <T as PortableTool>::Output

Source§

type Error = <T as PortableTool>::Error