pub struct ToolSpec {
pub name: String,
pub description: String,
pub required_fields: Vec<String>,
pub validators: Vec<Box<dyn ToolValidator>>,
pub circuit_breaker: Option<Arc<CircuitBreaker>>,
/* private fields */
}Expand description
Describes and implements a single callable tool.
Fields§
§name: StringShort identifier used in action strings (e.g. “search”).
description: StringHuman-readable description passed to the model as part of the system prompt.
required_fields: Vec<String>Field names that must be present in the JSON args object. Empty means no validation is performed.
validators: Vec<Box<dyn ToolValidator>>Custom argument validators run after required_fields and before the handler.
All validators must pass; the first failure short-circuits execution.
circuit_breaker: Option<Arc<CircuitBreaker>>Optional per-tool circuit breaker.
Implementations§
Source§impl ToolSpec
impl ToolSpec
Sourcepub fn new(
name: impl Into<String>,
description: impl Into<String>,
handler: impl Fn(Value) -> Value + Send + Sync + 'static,
) -> Self
pub fn new( name: impl Into<String>, description: impl Into<String>, handler: impl Fn(Value) -> Value + Send + Sync + 'static, ) -> Self
Construct a new ToolSpec from a synchronous handler closure.
The closure is wrapped in an async move block automatically.
Sourcepub fn new_async(
name: impl Into<String>,
description: impl Into<String>,
handler: impl Fn(Value) -> AsyncToolFuture + Send + Sync + 'static,
) -> Self
pub fn new_async( name: impl Into<String>, description: impl Into<String>, handler: impl Fn(Value) -> AsyncToolFuture + Send + Sync + 'static, ) -> Self
Construct a new ToolSpec from an async handler closure.
Sourcepub fn new_fallible(
name: impl Into<String>,
description: impl Into<String>,
handler: impl Fn(Value) -> Result<Value, String> + Send + Sync + 'static,
) -> Self
pub fn new_fallible( name: impl Into<String>, description: impl Into<String>, handler: impl Fn(Value) -> Result<Value, String> + Send + Sync + 'static, ) -> Self
Construct a new ToolSpec from a synchronous fallible handler closure.
Err(msg) is converted to {"error": msg, "ok": false}.
Sourcepub fn new_async_fallible(
name: impl Into<String>,
description: impl Into<String>,
handler: impl Fn(Value) -> AsyncToolResultFuture + Send + Sync + 'static,
) -> Self
pub fn new_async_fallible( name: impl Into<String>, description: impl Into<String>, handler: impl Fn(Value) -> AsyncToolResultFuture + Send + Sync + 'static, ) -> Self
Construct a new ToolSpec from an async fallible handler closure.
Err(msg) is converted to {"error": msg, "ok": false}.
Sourcepub fn with_required_fields(
self,
fields: impl IntoIterator<Item = impl Into<String>>,
) -> Self
pub fn with_required_fields( self, fields: impl IntoIterator<Item = impl Into<String>>, ) -> Self
Set the required fields that must be present in the JSON args object.
Accepts any iterable of string-like values so callers can pass
&["field1", "field2"], vec!["f".to_string()], or any other
IntoIterator<Item: Into<String>> without manual conversion.
Sourcepub fn with_validators(self, validators: Vec<Box<dyn ToolValidator>>) -> Self
pub fn with_validators(self, validators: Vec<Box<dyn ToolValidator>>) -> Self
Attach custom argument validators.
Validators run after required_fields checks and before the handler.
The first failing validator short-circuits execution.
Sourcepub fn with_circuit_breaker(self, cb: Arc<CircuitBreaker>) -> Self
pub fn with_circuit_breaker(self, cb: Arc<CircuitBreaker>) -> Self
Attach a circuit breaker to this tool spec.
Sourcepub fn with_description(self, desc: impl Into<String>) -> Self
pub fn with_description(self, desc: impl Into<String>) -> Self
Override the human-readable description after construction.
Sourcepub fn with_name(self, name: impl Into<String>) -> Self
pub fn with_name(self, name: impl Into<String>) -> Self
Override the tool name after construction.
Sourcepub fn required_field_count(&self) -> usize
pub fn required_field_count(&self) -> usize
Return the number of required fields configured for this tool.
Sourcepub fn has_required_fields(&self) -> bool
pub fn has_required_fields(&self) -> bool
Return true if this tool requires at least one field to be present in its args.
Sourcepub fn has_validators(&self) -> bool
pub fn has_validators(&self) -> bool
Return true if this tool has at least one custom argument validator attached.