Skip to main content

AgentTool

Trait AgentTool 

Source
pub trait AgentTool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn label(&self) -> &str;
    fn description(&self) -> &str;
    fn parameters_schema(&self) -> Value;
    fn execute<'life0, 'async_trait>(
        &'life0 self,
        params: Value,
        ctx: ToolContext,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

A tool the agent can call. Implement this trait for your tools.

Required Methods§

Source

fn name(&self) -> &str

Unique tool name (used in LLM tool_use)

Source

fn label(&self) -> &str

Human-readable label for UI

Source

fn description(&self) -> &str

Description for the LLM

Source

fn parameters_schema(&self) -> Value

JSON Schema for parameters

Source

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

Execute the tool.

The ctx parameter provides per-invocation context:

  • ctx.tool_call_id / ctx.tool_name — for correlation and logging
  • ctx.cancel — cancellation token; check is_cancelled() in long-running tools
  • ctx.on_update — optional callback for streaming partial ToolResults (UI/logging only)
  • ctx.on_progress — optional callback for user-facing progress text (ProgressMessage)

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§