Skip to main content

ToolMetadata

Struct ToolMetadata 

Source
#[non_exhaustive]
pub struct ToolMetadata { pub name: String, pub description: String, pub input_schema: Value, pub output_schema: Option<Value>, pub version: Option<String>, pub effect: ToolEffect, pub idempotent: bool, pub retry_hint: Option<RetryHint>, pub typical_duration: Option<Duration>, }
Expand description

Declarative description of a tool.

Every field is plain-data; constructed once (typically in the tool’s own new()) and returned by reference from Tool::metadata. The runtime treats this as authoritative — codecs render it into the on-the-wire ToolSpec, OTel layers stamp gen_ai.tool.* attributes from it, Approver defaults route off effect, and retry middleware honours retry_hint.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

Stable identifier the model uses to call this tool. Must be unique within a ToolRegistry. Conventionally snake_case.

§description: String

Human-readable description shown to the model. Used to help the model decide when to call this tool — write it like a function docstring.

§input_schema: Value

JSON Schema for the input payload that Tool::execute accepts. Codecs translate this into the vendor’s tool schema format.

§output_schema: Option<Value>

Optional JSON Schema describing the output shape. Vendors that support strict tool-output schemas (OpenAI’s strict: true, Anthropic’s response format hints) read this. None = untyped JSON.

§version: Option<String>

Optional version string. Surfaces in OTel (gen_ai.tool.version) and in audit events so operators can distinguish between tool revisions when behaviour changes.

§effect: ToolEffect

Side-effect classification. Drives default Approver behaviour (Destructive → require approval) and is rendered to the LLM so the model can reason about safety on its own.

§idempotent: bool

true when calling the tool repeatedly with the same input produces the same effect (no incremental change). Retry middleware uses this as the cheap binary version of retry_hint.is_some().

§retry_hint: Option<RetryHint>

Per-tool retry policy hint. None (the default) means the tool is not retried by middleware.

§typical_duration: Option<Duration>

Best-guess execution time for dashboards / scheduling. Used only as a hint — the runtime never enforces it as a deadline (use ExecutionContext::deadline for that).

Implementations§

Source§

impl ToolMetadata

Source

pub fn function( name: impl Into<String>, description: impl Into<String>, input_schema: Value, ) -> Self

Construct a function-tool descriptor with conservative defaults (effect = ReadOnly, no retry, no version). Customise via the with_* chain.

Source

pub fn with_output_schema(self, schema: Value) -> Self

Attach an output schema.

Source

pub fn with_version(self, version: impl Into<String>) -> Self

Attach a version string.

Source

pub const fn with_effect(self, effect: ToolEffect) -> Self

Override the side-effect classification.

Source

pub fn to_tool_spec(&self) -> ToolSpec

Project this metadata into the wire-shaped ToolSpec codecs encode for the model. Inspection helper used by crate::tools::Toolset::tool_specs and capability manifests. cache_control defaults to None — operators that need a per-tool cache directive set it on the ToolSpec itself.

Source

pub const fn with_idempotent(self, idempotent: bool) -> Self

Mark the tool idempotent — repeat calls with the same input produce the same effect.

Source

pub const fn with_retry_hint(self, hint: RetryHint) -> Self

Attach a retry hint. Implies idempotent = true because a non-idempotent tool that opts into retries is a bug.

Source

pub const fn with_typical_duration(self, duration: Duration) -> Self

Attach a typical-duration hint.

Trait Implementations§

Source§

impl Clone for ToolMetadata

Source§

fn clone(&self) -> ToolMetadata

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more