pub struct ToolSpec {
pub name: String,
pub description: String,
pub handler: AsyncToolHandler,
pub required_fields: Vec<String>,
pub circuit_breaker: Option<Arc<CircuitBreaker>>,
}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.
handler: AsyncToolHandlerAsync handler: receives JSON arguments, returns a future resolving to a JSON result.
required_fields: Vec<String>Field names that must be present in the JSON args object. Empty means no validation is performed.
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 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_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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToolSpec
impl !RefUnwindSafe for ToolSpec
impl Send for ToolSpec
impl Sync for ToolSpec
impl Unpin for ToolSpec
impl UnsafeUnpin for ToolSpec
impl !UnwindSafe for ToolSpec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more