Skip to main content

ToolExecutor

Trait ToolExecutor 

Source
pub trait ToolExecutor: Send + Sync {
    // Required methods
    fn specs(&self) -> Vec<ToolSpec>;
    fn execute<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        request: ToolRequest,
        ctx: &'life1 mut ToolContext<'life2>,
    ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;

    // Provided methods
    fn execute_owned<'life0, 'async_trait>(
        &'life0 self,
        request: ToolRequest,
        ctx: OwnedToolContext,
    ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait { ... }
    fn execute_approved<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        request: ToolRequest,
        approved_request: &'life1 ApprovalRequest,
        ctx: &'life2 mut ToolContext<'life3>,
    ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn execute_approved_owned<'life0, 'life1, 'async_trait>(
        &'life0 self,
        request: ToolRequest,
        approved_request: &'life1 ApprovalRequest,
        ctx: OwnedToolContext,
    ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Trait for executing tool calls with permission checking and interruption handling.

The agent loop calls execute for every tool call the model emits. If execution returns ToolExecutionOutcome::Interrupted, the loop collects user input and retries with execute_approved.

Required Methods§

Source

fn specs(&self) -> Vec<ToolSpec>

Returns the current specification for every available tool.

Source

fn execute<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, request: ToolRequest, ctx: &'life1 mut ToolContext<'life2>, ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Looks up the tool, evaluates permissions, and invokes it.

Provided Methods§

Source

fn execute_owned<'life0, 'async_trait>( &'life0 self, request: ToolRequest, ctx: OwnedToolContext, ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Looks up the tool, evaluates permissions, and invokes it using an owned execution context.

Source

fn execute_approved<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, request: ToolRequest, approved_request: &'life1 ApprovalRequest, ctx: &'life2 mut ToolContext<'life3>, ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Re-executes a tool call that was previously interrupted for approval.

The default implementation ignores approved_request and delegates to execute. BasicToolExecutor overrides this to skip the approval gate for the matching request.

Source

fn execute_approved_owned<'life0, 'life1, 'async_trait>( &'life0 self, request: ToolRequest, approved_request: &'life1 ApprovalRequest, ctx: OwnedToolContext, ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Re-executes a tool call that was previously interrupted for approval using an owned execution context.

Implementors§