mod args;
mod closure;
mod executor;
use crate::types::{ToolCall, ToolResult};
use async_trait::async_trait;
use futures::future::join_all;
pub use args::*;
pub(crate) use closure::*;
pub use executor::*;
pub use tiny_loop_macros::tool;
#[async_trait]
pub trait Tool {
async fn call(&self, args: String) -> String;
async fn call_timed(&self, call: ToolCall) -> ToolResult {
let start = std::time::SystemTime::now();
let content = self.call(call.function.arguments).await;
let elapsed = start.elapsed().unwrap();
ToolResult {
tool_message: crate::types::ToolMessage {
tool_call_id: call.id,
content,
},
timestamp: start + elapsed,
elapsed,
}
}
async fn call_batch(&self, args: Vec<ToolCall>) -> Vec<ToolResult> {
join_all(
args.into_iter()
.map(|call| self.call_timed(call))
.collect::<Vec<_>>(),
)
.await
}
}