1mod args;
2mod closure;
3mod executor;
4
5use crate::types::{ToolCall, ToolResult};
6use async_trait::async_trait;
7use futures::future::join_all;
8
9pub use args::*;
10pub(crate) use closure::*;
11pub use executor::*;
12pub use tiny_loop_macros::tool;
13
14#[async_trait]
20pub trait Tool {
21 async fn call(&self, args: String) -> String;
23
24 async fn call_timed(&self, call: ToolCall) -> ToolResult {
26 let start = std::time::SystemTime::now();
27 let content = self.call(call.function.arguments).await;
28 let elapsed = start.elapsed().unwrap();
29 ToolResult {
30 tool_message: crate::types::ToolMessage {
31 tool_call_id: call.id,
32 content,
33 },
34 timestamp: start + elapsed,
35 elapsed,
36 }
37 }
38
39 async fn call_batch(&self, args: Vec<ToolCall>) -> Vec<ToolResult> {
41 join_all(
42 args.into_iter()
43 .map(|call| self.call_timed(call))
44 .collect::<Vec<_>>(),
45 )
46 .await
47 }
48}