#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: StringStable identifier the model uses to call this tool. Must be
unique within a ToolRegistry. Conventionally snake_case.
description: StringHuman-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: ValueJSON 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: ToolEffectSide-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: booltrue 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
impl ToolMetadata
Sourcepub fn function(
name: impl Into<String>,
description: impl Into<String>,
input_schema: Value,
) -> Self
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.
Sourcepub fn with_output_schema(self, schema: Value) -> Self
pub fn with_output_schema(self, schema: Value) -> Self
Attach an output schema.
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Attach a version string.
Sourcepub const fn with_effect(self, effect: ToolEffect) -> Self
pub const fn with_effect(self, effect: ToolEffect) -> Self
Override the side-effect classification.
Sourcepub fn to_tool_spec(&self) -> ToolSpec
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.
Sourcepub const fn with_idempotent(self, idempotent: bool) -> Self
pub const fn with_idempotent(self, idempotent: bool) -> Self
Mark the tool idempotent — repeat calls with the same input produce the same effect.
Sourcepub const fn with_retry_hint(self, hint: RetryHint) -> Self
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.
Sourcepub const fn with_typical_duration(self, duration: Duration) -> Self
pub const fn with_typical_duration(self, duration: Duration) -> Self
Attach a typical-duration hint.
Trait Implementations§
Source§impl Clone for ToolMetadata
impl Clone for ToolMetadata
Source§fn clone(&self) -> ToolMetadata
fn clone(&self) -> ToolMetadata
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more