1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
//! # Tools-rs: A Tool Collection and Execution Framework
//!
//! Tools-rs provides a framework for building, registering, and executing tools
//! with automatic JSON schema generation for LLM integration.
//!
//! ## Quick Start
//!
//! ```rust
//! use tools_rs::{tool, collect_tools, call_tool_with_args};
//!
//! #[tool]
//! /// Adds two numbers together
//! async fn add(a: i32, b: i32) -> i32 {
//! a + b
//! }
//!
//! #[tokio::main]
//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let tools = collect_tools();
//! let result = call_tool_with_args(&tools, "add", &[1, 2]).await?;
//! println!("Result: {}", result);
//! Ok(())
//! }
//! ```
//!
//! ## Features
//!
//! - **Automatic Registration**: Use `#[tool]` to automatically register functions
//! - **JSON Schema Generation**: Automatic schema generation for LLM integration
//! - **Type Safety**: Full type safety with JSON serialization at boundaries
//! - **Async Support**: Built for async/await from the ground up
//! - **Error Handling**: Comprehensive error types with context
//!
//! ## Manual Registration
//!
//! ```rust
//! use tools_rs::ToolCollection;
//!
//! # fn example() -> Result<(), tools_rs::ToolError> {
//! let mut tools: ToolCollection = ToolCollection::new();
//! tools.register(
//! "greet",
//! "Greets a person",
//! |name: String| async move { format!("Hello, {}!", name) },
//! (),
//! )?;
//! # Ok(())
//! # }
//! ```
// Re-export core functionality
pub use ;
// Re-export schema functionality (trait from tools_core)
pub use ToolSchema;
// Re-export macros (both tool attribute and ToolSchema derive)
pub use ;
/// Convenient imports for common usage patterns.
///
/// Import everything you typically need with:
/// ```rust
/// use tools_rs::prelude::*;
/// ```
/// Collect all tools registered via the `#[tool]` macro.
///
/// This function discovers all tools that were registered at compile time
/// using the `#[tool]` attribute macro.
///
/// # Example
///
/// ```rust
/// use tools_rs::{collect_tools, list_tool_names};
///
/// let tools = collect_tools();
/// println!("Available tools: {:?}", list_tool_names(&tools));
/// ```
/// Generate function declarations in JSON format for LLM consumption.
///
/// This is equivalent to `collect_tools().json()` but provides a more
/// convenient API for the common use case of generating LLM-compatible
/// function declarations.
///
/// # Example
///
/// ```rust
/// use tools_rs::function_declarations;
///
/// let declarations = function_declarations()?;
/// // Send to LLM for function calling
/// # Ok::<(), tools_rs::ToolError>(())
/// ```
/// Call a tool by name with JSON arguments.
///
/// This is a convenience function that combines tool collection and execution
/// in a single call. Useful for simple scenarios where you don't need to
/// manage the tool collection yourself.
///
/// # Arguments
///
/// * `name` - The name of the tool to call
/// * `arguments` - JSON value containing the arguments
///
/// # Example
///
/// ```rust
/// use tools_rs::call_tool;
/// use serde_json::json;
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let result = call_tool("add", json!({"a": 1, "b": 2})).await?;
/// # Ok(())
/// # }
/// ```
pub async
/// Call a tool by name with typed arguments.
///
/// This function provides a more ergonomic API for calling tools when you
/// have typed arguments that can be serialized to JSON.
///
/// # Arguments
///
/// * `name` - The name of the tool to call
/// * `args` - Arguments that implement `serde::Serialize`
///
/// # Example
///
/// ```rust
/// use tools_rs::call_tool_with;
/// use serde::Serialize;
///
/// #[derive(Serialize)]
/// struct AddArgs { a: i32, b: i32 }
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let result = call_tool_with("add", &AddArgs { a: 1, b: 2 }).await?;
/// # Ok(())
/// # }
/// ```
pub async
/// Call a tool by name with JSON arguments on a given collection.
///
/// # Example
///
/// ```rust
/// use tools_rs::{collect_tools, call_tool_by_name};
/// use serde_json::json;
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let tools = collect_tools();
/// let result = call_tool_by_name(&tools, "add", json!([1, 2])).await?;
/// # Ok(())
/// # }
/// ```
pub async
/// Call a tool by name with typed arguments on a given collection.
///
/// # Example
///
/// ```rust
/// use tools_rs::{collect_tools, call_tool_with_args};
///
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let tools = collect_tools();
/// let result = call_tool_with_args(&tools, "add", &[1, 2]).await?;
/// # Ok(())
/// # }
/// ```
pub async
/// List all available tool names in a collection.
///
/// # Example
///
/// ```rust
/// use tools_rs::{collect_tools, list_tool_names};
///
/// let tools = collect_tools();
/// let names = list_tool_names(&tools);
/// println!("Available tools: {:?}", names);
/// ```