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 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn drain_catalog_events(&self) -> Vec<ToolCatalogEvent> { ... }
    fn execute_owned<'life0, 'async_trait>(
        &'life0 self,
        request: ToolRequest,
        ctx: OwnedToolContext,
    ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: '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 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: '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 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: '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 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

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

Provided Methods§

Source

fn drain_catalog_events(&self) -> Vec<ToolCatalogEvent>

Drains any pending dynamic catalog events.

Static executors return an empty list. Dynamic executors should use interior mutability to return each catalog event once.

Source

fn execute_owned<'life0, 'async_trait>( &'life0 self, request: ToolRequest, ctx: OwnedToolContext, ) -> Pin<Box<dyn Future<Output = ToolExecutionOutcome> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: '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 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: '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 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<T> ToolExecutor for Arc<T>
where T: ToolExecutor + ?Sized,

Source§

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

Source§

fn drain_catalog_events(&self) -> Vec<ToolCatalogEvent>

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 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Arc<T>: 'async_trait,

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 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Arc<T>: 'async_trait,

Implementors§