pub struct ToolExecutor { /* private fields */ }Expand description
Tool executor with workspace sandboxing
This is the main entry point for tool execution. It wraps the ToolRegistry and provides backward-compatible API. Includes file version history tracking for write/edit/patch operations.
Defense-in-depth: An optional permission policy can be set to block denied tools even if the caller bypasses the agent loop’s authorization.
Implementations§
Source§impl ToolExecutor
impl ToolExecutor
pub fn new(workspace: String) -> Self
Sourcepub fn set_guard_policy(&mut self, policy: Arc<RwLock<PermissionPolicy>>)
pub fn set_guard_policy(&mut self, policy: Arc<RwLock<PermissionPolicy>>)
Set a defense-in-depth permission policy.
When set, every tool execution is checked against this policy.
Tools that match a Deny rule are blocked before execution.
This is a safety net for code paths that bypass the agent loop.
Sourcepub fn registry(&self) -> &ToolRegistry
pub fn registry(&self) -> &ToolRegistry
Get the tool registry for dynamic tool registration
Sourcepub fn register_dynamic_tool(&self, tool: Arc<dyn Tool>)
pub fn register_dynamic_tool(&self, tool: Arc<dyn Tool>)
Register a dynamic tool at runtime (e.g., MCP tools, LSP tools, task tool). The tool becomes immediately available in all future tool executions.
Sourcepub fn unregister_dynamic_tool(&self, name: &str)
pub fn unregister_dynamic_tool(&self, name: &str)
Unregister a dynamic tool by name
Sourcepub fn file_history(&self) -> &Arc<FileHistory>
pub fn file_history(&self) -> &Arc<FileHistory>
Get the file version history tracker
Sourcepub async fn execute(&self, name: &str, args: &Value) -> Result<ToolResult>
pub async fn execute(&self, name: &str, args: &Value) -> Result<ToolResult>
Execute a tool by name using the server-level default context
Sourcepub async fn execute_with_context(
&self,
name: &str,
args: &Value,
ctx: &ToolContext,
) -> Result<ToolResult>
pub async fn execute_with_context( &self, name: &str, args: &Value, ctx: &ToolContext, ) -> Result<ToolResult>
Execute a tool by name with a per-session context
Sourcepub fn definitions(&self) -> Vec<ToolDefinition>
pub fn definitions(&self) -> Vec<ToolDefinition>
Get all tool definitions for LLM