pub struct ToolExecutor { /* private fields */ }Expand description
Policy-aware tool executor
This executor ensures that every tool invocation passes through ToolPolicy::evaluate() before execution. Policy decisions are emitted as events for audit trail when an emitter is configured.
Implementations§
Source§impl ToolExecutor
impl ToolExecutor
Sourcepub fn new(policy: ToolPolicy) -> Self
pub fn new(policy: ToolPolicy) -> Self
Create a new tool executor with the given policy
Create with a shared policy
Sourcepub fn with_emitter(self, emitter: EventEmitter) -> Self
pub fn with_emitter(self, emitter: EventEmitter) -> Self
Configure an event emitter for policy decision audit trail
Sourcepub fn set_emitter(&mut self, emitter: EventEmitter)
pub fn set_emitter(&mut self, emitter: EventEmitter)
Set the event emitter for policy decision audit trail
Sourcepub async fn execute(
&self,
tool: &dyn Tool,
args: Value,
ctx: &ToolExecutionContext,
) -> Result<Value, ToolExecutionError>
pub async fn execute( &self, tool: &dyn Tool, args: Value, ctx: &ToolExecutionContext, ) -> Result<Value, ToolExecutionError>
Execute a tool with policy enforcement
This is the ONLY way to execute tools - it ensures policy is always checked. Policy decisions are emitted as events for audit trail when an emitter is configured.
Sourcepub async fn execute_sequence(
&self,
tools: &[(Arc<dyn Tool>, Value)],
ctx: &ToolExecutionContext,
) -> Result<Vec<Value>, ToolExecutionError>
pub async fn execute_sequence( &self, tools: &[(Arc<dyn Tool>, Value)], ctx: &ToolExecutionContext, ) -> Result<Vec<Value>, ToolExecutionError>
Execute multiple tools in sequence, stopping on first policy denial
Sourcepub fn is_allowed(&self, tool_name: &str, ctx: &ToolExecutionContext) -> bool
pub fn is_allowed(&self, tool_name: &str, ctx: &ToolExecutionContext) -> bool
Check if a tool would be allowed by policy (without executing)
Sourcepub fn get_permissions(&self, tool_name: &str) -> &ToolPermissions
pub fn get_permissions(&self, tool_name: &str) -> &ToolPermissions
Get the permissions for a tool
Sourcepub fn policy(&self) -> &ToolPolicy
pub fn policy(&self) -> &ToolPolicy
Get the policy reference