pub struct ToolExecutor { /* private fields */ }Expand description
Enhanced tool executor with built-in registry and fluent API
Implementations§
Source§impl ToolExecutor
impl ToolExecutor
Sourcepub fn builder() -> ExecutorBuilder
pub fn builder() -> ExecutorBuilder
Create an executor builder for fluent API
Sourcepub fn with_cache_enabled(self, enabled: bool) -> Self
pub fn with_cache_enabled(self, enabled: bool) -> Self
Enable or disable tool call result caching
Sourcepub fn with_cache_ttl(self, ttl: Duration) -> Self
pub fn with_cache_ttl(self, ttl: Duration) -> Self
Set cache TTL (time-to-live)
Sourcepub fn with_cache_max_size(self, size: usize) -> Self
pub fn with_cache_max_size(self, size: usize) -> Self
Set maximum cache size
Sourcepub fn clear_cache(&self)
pub fn clear_cache(&self)
Clear the cache
Sourcepub fn invalidate_cache_for_tool(&self, tool_name: &str)
pub fn invalidate_cache_for_tool(&self, tool_name: &str)
Invalidate cache for a specific tool
Sourcepub fn cache_stats(&self) -> CacheStats
pub fn cache_stats(&self) -> CacheStats
Get cache statistics
Sourcepub fn add_dyn_tool(&self, tool: Box<dyn DynTool>) -> &Self
pub fn add_dyn_tool(&self, tool: Box<dyn DynTool>) -> &Self
Chain-friendly: add a dynamic tool (panics on error)
Sourcepub fn try_add_dyn_tool(&self, tool: Box<dyn DynTool>) -> &Self
pub fn try_add_dyn_tool(&self, tool: Box<dyn DynTool>) -> &Self
Chain-friendly: try to add a dynamic tool (ignores error)
Sourcepub fn unregister(&self, name: &str) -> ToolResult<()>
pub fn unregister(&self, name: &str) -> ToolResult<()>
Unregister a tool
Sourcepub fn input_schema(&self, name: &str) -> Option<Value>
pub fn input_schema(&self, name: &str) -> Option<Value>
Get input schema for a tool
Sourcepub fn tool_names(&self) -> Vec<String>
pub fn tool_names(&self) -> Vec<String>
List tool names
Sourcepub async fn execute(
&self,
tool_name: &str,
input: Value,
) -> ToolResult<ExecutionResult>
pub async fn execute( &self, tool_name: &str, input: Value, ) -> ToolResult<ExecutionResult>
Execute a tool with detailed result and exponential backoff
Sourcepub async fn execute_simple(
&self,
tool_name: &str,
input: Value,
) -> ToolResult<Value>
pub async fn execute_simple( &self, tool_name: &str, input: Value, ) -> ToolResult<Value>
Execute a tool and return only the result
Sourcepub fn add_functions_from_dir_with_registry(
&self,
dir: impl AsRef<Path>,
handlers: &HashMap<String, Arc<dyn Fn(Value) -> Pin<Box<dyn Future<Output = ToolResult<Value>> + Send>> + Send + Sync>>,
strict: bool,
) -> ToolResult<Vec<String>>
pub fn add_functions_from_dir_with_registry( &self, dir: impl AsRef<Path>, handlers: &HashMap<String, Arc<dyn Fn(Value) -> Pin<Box<dyn Future<Output = ToolResult<Value>> + Send>> + Send + Sync>>, strict: bool, ) -> ToolResult<Vec<String>>
Bulk load function specs from a directory of .json files and register them with handlers.
- Each file should contain either of the following shapes:
- {“name”:…, “description”:…, “parameters”: {…}}
- {“type”:“function”, “function”: {“name”:…, “description”:…, “parameters”: {…}}}
handlersmaps functionname-> handler closurestrict: when true, missing handler for any spec will return error; when false, specs without handlers are skipped
Returns the list of function names successfully registered.
pub async fn execute_tool_calls_parallel( &self, calls: &[ToolCallMessage], ) -> Vec<TextMessage>
Sourcepub async fn execute_tool_calls_ordered(
&self,
calls: &[ToolCallMessage],
) -> Vec<TextMessage>
pub async fn execute_tool_calls_ordered( &self, calls: &[ToolCallMessage], ) -> Vec<TextMessage>
Execute LLM tool_calls in parallel with result ordering preserved
This method guarantees that results are returned in the same order as the input calls, which is important for maintaining conversation context in LLM interactions.
Behavior:
- Parses each ToolCallMessage’s function.arguments (stringified JSON supported)
- Runs all tools concurrently using this executor
- Preserves the original order of tool calls in results
- Captures errors per-call and encodes them as JSON
- Preserves tool_call
idby emitting TextMessage::tool_with_id when present
Returns:
- Vec
in the same order as input calls, ready for ChatCompletion
Sourcepub fn export_tool_as_function(&self, name: &str) -> Option<Tools>
pub fn export_tool_as_function(&self, name: &str) -> Option<Tools>
Export a single registered tool as Tools::Function (for LLM function calling)
Sourcepub fn export_all_tools_as_functions(&self) -> Vec<Tools>
pub fn export_all_tools_as_functions(&self) -> Vec<Tools>
Export all registered tools as a VecTools::Function
Sourcepub fn export_tools_filtered<F>(&self, filter: F) -> Vec<Tools>
pub fn export_tools_filtered<F>(&self, filter: F) -> Vec<Tools>
Export all registered tools with a metadata filter as Tools::Function
Sourcepub fn config(&self) -> &ExecutionConfig
pub fn config(&self) -> &ExecutionConfig
Get the config
Trait Implementations§
Source§impl Clone for ToolExecutor
impl Clone for ToolExecutor
Source§fn clone(&self) -> ToolExecutor
fn clone(&self) -> ToolExecutor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more