pub struct ToolParameter {
pub name: String,
pub param_type: ToolParameterType,
pub description: Option<String>,
pub required: bool,
pub default: Option<Value>,
pub items: Option<Box<ToolParameterType>>,
pub properties: Option<HashMap<String, ToolParameter>>,
}Expand description
Defines a parameter for a tool
Fields§
§name: StringParameter name.
param_type: ToolParameterTypeParameter value type.
description: Option<String>Human-readable description.
required: boolWhether the caller must provide this parameter.
default: Option<Value>Optional default value.
items: Option<Box<ToolParameterType>>For array types, specifies the type of items
properties: Option<HashMap<String, ToolParameter>>For object types, specifies nested properties
Implementations§
Source§impl ToolParameter
impl ToolParameter
Sourcepub fn new(name: impl Into<String>, param_type: ToolParameterType) -> Self
pub fn new(name: impl Into<String>, param_type: ToolParameterType) -> Self
Define a new tool parameter with the provided name and type.
Sourcepub fn with_description(self, description: impl Into<String>) -> Self
pub fn with_description(self, description: impl Into<String>) -> Self
Add a human readable description that will surface in generated schemas.
Sourcepub fn with_default(self, default: Value) -> Self
pub fn with_default(self, default: Value) -> Self
Provide a default value that will be used when the LLM omits the parameter.
Sourcepub fn with_items(self, item_type: ToolParameterType) -> Self
pub fn with_items(self, item_type: ToolParameterType) -> Self
For array parameters, declare the type of the contained items.
Sourcepub fn with_properties(self, properties: HashMap<String, ToolParameter>) -> Self
pub fn with_properties(self, properties: HashMap<String, ToolParameter>) -> Self
For object parameters, describe the nested properties.
Sourcepub fn to_json_schema(&self) -> Value
pub fn to_json_schema(&self) -> Value
Converts this parameter to a JSON Schema snippet suitable for native tool-calling.
The generated schema follows [JSON Schema draft-07] conventions accepted by all major providers (OpenAI, Anthropic, Grok, Gemini).
ToolParameterType | Schema produced |
|---|---|
String | {"type":"string"} |
Number | {"type":"number"} |
Integer | {"type":"integer"} |
Boolean | {"type":"boolean"} |
Array | {"type":"array","items":{...}} |
Object | {"type":"object","properties":{...},"required":[...]} |
§Example
use cloudllm::tool_protocol::{ToolParameter, ToolParameterType};
let param = ToolParameter::new("query", ToolParameterType::String)
.with_description("Search query string")
.required();
let schema = param.to_json_schema();
assert_eq!(schema["type"], "string");
assert_eq!(schema["description"], "Search query string");Trait Implementations§
Source§impl Clone for ToolParameter
impl Clone for ToolParameter
Source§fn clone(&self) -> ToolParameter
fn clone(&self) -> ToolParameter
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more