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: Vec<String>) -> Self
pub fn with_required_fields(self, fields: Vec<String>) -> Self
Set the required fields that must be present in the JSON args object.
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.