pub struct ToolExecutor { /* private fields */ }Expand description
Tool executor with automatic audit logging and timeout protection.
The executor provides a safe, audited interface to execute tools:
- Validates arguments against tool’s schema
- Executes with timeout protection
- Hashes results for Merkle chain
- Logs execution to audit trail (if configured)
§Example
ⓘ
use vex_llm::{ToolExecutor, ToolRegistry};
let registry = ToolRegistry::with_builtins();
let executor = ToolExecutor::new(registry);
let result = executor
.execute("calculator", json!({"expression": "2+2"}))
.await?;
println!("Result: {}", result.output);
println!("Hash: {}", result.hash);Implementations§
Source§impl ToolExecutor
impl ToolExecutor
Sourcepub fn new(registry: ToolRegistry) -> Self
pub fn new(registry: ToolRegistry) -> Self
Create a new executor with the given registry
Sourcepub fn without_audit(registry: ToolRegistry) -> Self
pub fn without_audit(registry: ToolRegistry) -> Self
Create executor with audit logging disabled
Sourcepub fn with_max_parallel(self, max: usize) -> Self
pub fn with_max_parallel(self, max: usize) -> Self
Set maximum parallel executions
Sourcepub fn with_allowed_capabilities(self, caps: Vec<Capability>) -> Self
pub fn with_allowed_capabilities(self, caps: Vec<Capability>) -> Self
Set allowed capabilities for the sandbox
Sourcepub async fn execute(
&self,
tool_name: &str,
args: Value,
) -> Result<ToolResult, ToolError>
pub async fn execute( &self, tool_name: &str, args: Value, ) -> Result<ToolResult, ToolError>
Execute a tool by name with given arguments.
§Arguments
tool_name- Name of the tool to executeargs- JSON arguments to pass to the tool
§Returns
Ok(ToolResult)- Execution result with hash for verificationErr(ToolError)- If tool not found, validation failed, execution error, or timeout
§Security
- Tool lookup prevents arbitrary code execution
- Timeout prevents DoS from hanging tools
- Result hash enables tamper detection
Sourcepub async fn execute_parallel(
&self,
calls: Vec<(String, Value)>,
) -> Vec<Result<ToolResult, ToolError>>
pub async fn execute_parallel( &self, calls: Vec<(String, Value)>, ) -> Vec<Result<ToolResult, ToolError>>
Execute multiple tools in parallel.
§Arguments
calls- Vector of (tool_name, args) pairs
§Returns
Vector of results in the same order as input. Each result is independent (one failure doesn’t affect others).
§Security
- Respects max_parallel limit to prevent resource exhaustion
- Each tool has its own timeout
Sourcepub fn registry(&self) -> &ToolRegistry
pub fn registry(&self) -> &ToolRegistry
Get a reference to the tool registry
Sourcepub fn registry_mut(&mut self) -> &mut ToolRegistry
pub fn registry_mut(&mut self) -> &mut ToolRegistry
Get a mutable reference to the tool registry
Sourcepub fn tool_names(&self) -> Vec<&str>
pub fn tool_names(&self) -> Vec<&str>
List all available tool names
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToolExecutor
impl !RefUnwindSafe for ToolExecutor
impl Send for ToolExecutor
impl Sync for ToolExecutor
impl Unpin for ToolExecutor
impl !UnwindSafe for ToolExecutor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more