Skip to main content

AsyncTool

Trait AsyncTool 

Source
pub trait AsyncTool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn spec(&self) -> Result<ToolSpec>;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        ctx: ToolContext,
        args: Value,
    ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn concurrency(&self) -> ToolConcurrency { ... }
}
Expand description

Async, context-aware tool interface for advanced Rust tools.

This trait extends Appam’s original synchronous Tool interface with runtime metadata and managed-state access while remaining additive and opt-in. Legacy tools continue to implement Tool unchanged; new stateful or asynchronous tools should implement AsyncTool.

§Concurrency

Tools are treated as ToolConcurrency::SerialOnly unless they explicitly opt into ToolConcurrency::ParallelSafe. This avoids surprising races for tools that mutate shared state or depend on side-effect ordering.

Required Methods§

Source

fn name(&self) -> &str

Return the unique, stable function name for this tool.

Source

fn spec(&self) -> Result<ToolSpec>

Return the tool specification exposed to the model.

Source

fn execute<'life0, 'async_trait>( &'life0 self, ctx: ToolContext, args: Value, ) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute the tool with runtime metadata and JSON arguments.

The provided ToolContext contains stable identifiers for the current session and tool call plus managed state lookup helpers.

§Errors

Returns an error if arguments are invalid, required managed state is missing, execution fails, or the result cannot be serialized.

Provided Methods§

Source

fn concurrency(&self) -> ToolConcurrency

Return the concurrency policy for this tool.

Implementations should keep the default unless concurrent execution is demonstrably safe with respect to shared state and external side effects.

Implementors§