pub struct ToolDefinition {
pub name: String,
pub description: String,
pub parameters: Value,
}Expand description
工具定义 — 发送给 LLM 的 schema。
对应 LLM API 中 tools 数组的每个元素,包含名称、描述和参数 JSON Schema。
LLM 据此决定何时调用工具以及如何构造参数。
§Examples
use katu_core::ToolDefinition;
use serde_json::json;
let tool = ToolDefinition::new(
"read_file",
"Read the contents of a file at the given path",
json!({
"type": "object",
"properties": {
"path": { "type": "string", "description": "File path" }
},
"required": ["path"]
}),
);
assert_eq!(tool.name, "read_file");Fields§
§name: String工具名称 — LLM 在 tool_call 中引用的唯一标识。
命名约定:snake_case,如 "read_file", "bash", "web_search"。
description: String工具描述 — LLM 据此决定何时以及为什么调用此工具。
应该清晰描述工具的功能、适用场景和限制。
parameters: Value参数的 JSON Schema — 定义工具接受的输入格式。
必须是一个 {"type": "object", "properties": {...}} 形式的 JSON Schema。
LLM 根据此 schema 构造 tool_call.arguments。
Implementations§
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
Source§impl PartialEq for ToolDefinition
impl PartialEq for ToolDefinition
Source§fn eq(&self, other: &ToolDefinition) -> bool
fn eq(&self, other: &ToolDefinition) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ToolDefinition
impl Serialize for ToolDefinition
impl StructuralPartialEq 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
Mutably borrows from an owned value. Read more