1use serde::{Deserialize, Serialize};
4use serde_json::Value;
5
6use crate::JsonObject;
7use crate::ids::ToolCallId;
8
9#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
14#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
15#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
16pub struct Tool {
17 pub name: String,
19 pub description: String,
21 #[serde(default)]
23 pub parameters: Value,
24 #[serde(default, skip_serializing_if = "Option::is_none")]
26 #[cfg_attr(
27 feature = "schemars",
28 schemars(with = "Option<std::collections::BTreeMap<String, serde_json::Value>>")
29 )]
30 #[cfg_attr(feature = "utoipa", schema(value_type = Option<Object>))]
31 pub metadata: Option<JsonObject>,
32}
33
34impl Tool {
35 pub fn new(
37 name: impl Into<String>,
38 description: impl Into<String>,
39 parameters: impl Into<Value>,
40 ) -> Self {
41 Self {
42 name: name.into(),
43 description: description.into(),
44 parameters: parameters.into(),
45 metadata: None,
46 }
47 }
48}
49
50#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
55#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
56#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
57pub enum ToolCallKind {
58 #[default]
60 #[serde(rename = "function")]
61 Function,
62}
63
64#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
66#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
67#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
68pub struct FunctionCall {
69 pub name: String,
71 pub arguments: String,
76}
77
78#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
80#[serde(rename_all = "camelCase")]
81#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
82#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
83pub struct ToolCall {
84 pub id: ToolCallId,
86 #[serde(rename = "type", default)]
88 pub kind: ToolCallKind,
89 pub function: FunctionCall,
91 #[serde(default, skip_serializing_if = "Option::is_none")]
93 pub encrypted_value: Option<String>,
94 #[serde(
100 default,
101 deserialize_with = "crate::serde_util::reject_null",
102 skip_serializing_if = "Option::is_none"
103 )]
104 #[cfg_attr(
105 feature = "schemars",
106 schemars(with = "Option<std::collections::BTreeMap<String, serde_json::Value>>")
107 )]
108 #[cfg_attr(feature = "utoipa", schema(value_type = Option<Object>))]
109 pub metadata: Option<JsonObject>,
110}
111
112impl ToolCall {
113 pub fn new(
115 id: impl Into<ToolCallId>,
116 name: impl Into<String>,
117 arguments: impl Into<String>,
118 ) -> Self {
119 Self {
120 id: id.into(),
121 kind: ToolCallKind::Function,
122 function: FunctionCall {
123 name: name.into(),
124 arguments: arguments.into(),
125 },
126 encrypted_value: None,
127 metadata: None,
128 }
129 }
130}