Skip to main content

tiny_loop/tool/
executor.rs

1mod parallel;
2mod sequential;
3
4use super::Tool;
5use crate::types::{ToolCall, ToolResult};
6use async_trait::async_trait;
7
8pub use parallel::*;
9pub use sequential::*;
10
11/// Executes tool calls with different strategies (parallel, sequential, etc.)
12#[async_trait]
13pub trait ToolExecutor {
14    /// Adds a tool to the executor. Returns the previous tool with the same name if it exists.
15    fn add(&mut self, name: String, tool: Box<dyn Tool + Sync>) -> Option<Box<dyn Tool + Sync>>;
16
17    /// Executes the given tool calls and returns the results with timing metadata.
18    async fn execute(&self, calls: Vec<ToolCall>) -> Vec<ToolResult>;
19}
20
21/// Creates a ToolResult for a tool not found error
22fn tool_not_found_result(call_id: String, tool_name: &str) -> ToolResult {
23    ToolResult {
24        tool_message: crate::types::ToolMessage {
25            tool_call_id: call_id,
26            content: format!("Tool '{}' not found", tool_name),
27        },
28        timestamp: std::time::SystemTime::now(),
29        elapsed: std::time::Duration::ZERO,
30    }
31}