#[non_exhaustive]pub struct ToolDefinition {
pub name: String,
pub description: String,
pub parameter_schema: Value,
pub effect: ToolEffect,
pub output_sanitization: OutputSanitization,
/* private fields */
}Expand description
Describes a custom tool that can be registered with an agent.
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: StringUnique tool name (e.g. "flash_device").
description: StringHuman-readable description shown to the model.
parameter_schema: ValueJSON Schema describing the tool’s parameters.
effect: ToolEffectExecution effect classification of the tool.
output_sanitization: OutputSanitizationAutomatic prompt-injection sanitization policy applied to the tool’s output.
Implementations§
Source§impl ToolDefinition
impl ToolDefinition
Sourcepub fn new(
name: impl Into<String>,
description: impl Into<String>,
parameter_schema: Value,
) -> Self
pub fn new( name: impl Into<String>, description: impl Into<String>, parameter_schema: Value, ) -> Self
Construct a ToolDefinition with default ToolEffect::Mutating
and the secure default OutputSanitization::SanitizeTokens.
Sourcepub fn from_schema<T: JsonSchema>(
name: impl Into<String>,
description: impl Into<String>,
) -> Result<Self, Error>
pub fn from_schema<T: JsonSchema>( name: impl Into<String>, description: impl Into<String>, ) -> Result<Self, Error>
Construct a ToolDefinition directly from a parameter struct T implementing schemars::JsonSchema.
§Errors
Returns the serde_json::Error if the generated schema cannot be converted to a JSON value.
Sourcepub fn with_effect(
name: impl Into<String>,
description: impl Into<String>,
parameter_schema: Value,
effect: ToolEffect,
) -> Self
pub fn with_effect( name: impl Into<String>, description: impl Into<String>, parameter_schema: Value, effect: ToolEffect, ) -> Self
Construct a ToolDefinition with an explicit ToolEffect.
Sourcepub const fn with_output_sanitization(
self,
sanitization: OutputSanitization,
) -> Self
pub const fn with_output_sanitization( self, sanitization: OutputSanitization, ) -> Self
Attach an OutputSanitization policy to this ToolDefinition. Chainable.
Sourcepub fn set_parameter_schema(&mut self, parameter_schema: Value)
pub fn set_parameter_schema(&mut self, parameter_schema: Value)
Update parameter_schema and invalidate any cached JSON serialization.
Sourcepub fn parameter_schema_mut(&mut self) -> &mut Value
pub fn parameter_schema_mut(&mut self) -> &mut Value
Borrow parameter_schema mutably and invalidate any cached JSON serialization.
Sourcepub fn parameter_schema_json(&self) -> &str
pub fn parameter_schema_json(&self) -> &str
Return the pre-serialized JSON schema string (&str), lazily derived
from parameter_schema.
Sourcepub fn parameter_schema_json_arc(&self) -> &Arc<str> ⓘ
pub fn parameter_schema_json_arc(&self) -> &Arc<str> ⓘ
Return the pre-serialized JSON schema string (&Arc<str>), lazily derived
from parameter_schema.
Sourcepub const fn is_idempotent(&self) -> bool
pub const fn is_idempotent(&self) -> bool
Whether repeated invocations with identical arguments are side-effect free / idempotent.
Preserved for backward compatibility.
Trait Implementations§
Source§impl Clone for ToolDefinition
impl Clone for ToolDefinition
Source§impl Debug for ToolDefinition
impl Debug for ToolDefinition
Source§impl<'de> Deserialize<'de> for ToolDefinition
impl<'de> Deserialize<'de> for ToolDefinition
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for ToolDefinition
Source§impl PartialEq for ToolDefinition
impl PartialEq for ToolDefinition
Auto Trait Implementations§
impl !Freeze for ToolDefinition
impl RefUnwindSafe for ToolDefinition
impl Send for ToolDefinition
impl Sync for ToolDefinition
impl Unpin for ToolDefinition
impl UnsafeUnpin for ToolDefinition
impl UnwindSafe for ToolDefinition
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.