pub struct ToolDefinition {
pub name: String,
pub description: String,
pub parameters: Value,
pub cache_control: Option<CacheControl>,
}Expand description
工具定义(纯数据,协议层)。
Schema 由 schemars 在编译期生成,经清洗后存入 parameters 字段。
Provider 将此结构序列化后发送给 LLM。
与 ExecutableTool 的区别:
ToolDefinition(core):纯数据,Provider 序列化发送给 LLMExecutableTool(core):可执行,Agent 调用时查找并执行
Fields§
§name: String工具名称
description: String工具描述
parameters: ValueJSON Schema 参数定义
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>() -> ToolSchema
pub fn compute_and_clean_schema<S: JsonSchema>() -> ToolSchema
从 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