pub struct ToolDefinition {
pub name: String,
pub description: String,
pub parameters: Value,
pub cache_control: Option<CacheControl>,
}Expand description
工具定义(输入侧)。
Schema 由 schemars 在编译期生成,经 compute_and_clean_schema 清洗后
存入 parameters 字段。Codec 层按 Provider 需求进行二次适配。
Fields§
§name: String§description: String§parameters: Value§cache_control: Option<CacheControl>缓存控制标记。Anthropic 支持 Tool Definition 级别的缓存。
Implementations§
Source§impl ToolDefinition
impl ToolDefinition
Sourcepub fn with_cache(self, cache: CacheControl) -> Self
pub fn with_cache(self, cache: CacheControl) -> Self
克隆并设置缓存标记。
Sourcepub fn compute_and_clean_schema<S: JsonSchema>() -> Value
pub fn compute_and_clean_schema<S: JsonSchema>() -> Value
从 schemars::JsonSchema 类型计算并清洗 JSON Schema。
供 #[tool] 宏生成的 LazyLock 调用,不在泛型函数中使用 LazyLock。
清洗规则: 去除 $schema, $id, title, description 等根部元数据,
保留 type, properties, required, definitions 等核心 JSON Schema 字段。
Trait Implementations§
Source§impl Clone for ToolDefinition
impl Clone for ToolDefinition
Source§fn clone(&self) -> ToolDefinition
fn clone(&self) -> ToolDefinition
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more