Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn call<'life0, 'life1, 'async_trait>(
        &'life0 self,
        input: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn description(&self) -> &str { ... }
    fn openai_tool_spec(&self) -> Option<Value> { ... }
    fn is_enabled<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _ctx: &'life1 AgentContext,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn call_with_context<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        ctx: &'life1 AgentContext,
        _tool_call_id: Option<&'life2 str>,
        input: &'life3 str,
    ) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
}
Expand description

Basic tool trait comparable to Python FunctionTool.

Required Methods§

Source

fn name(&self) -> &str

Source

fn call<'life0, 'life1, 'async_trait>( &'life0 self, input: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the tool with a string input and return a string output.

Provided Methods§

Source

fn description(&self) -> &str

Source

fn openai_tool_spec(&self) -> Option<Value>

Optional OpenAI Chat Completions tool spec for this tool. Return None if the tool shouldn’t be exposed to the model.

Source

fn is_enabled<'life0, 'life1, 'async_trait>( &'life0 self, _ctx: &'life1 AgentContext, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Whether the tool is enabled in the current context.

Source

fn call_with_context<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, ctx: &'life1 AgentContext, _tool_call_id: Option<&'life2 str>, input: &'life3 str, ) -> Pin<Box<dyn Future<Output = Result<String, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Optional context-aware call. Default delegates to call.

Implementors§

Source§

impl<F> Tool for FunctionTool<F>
where F: Fn(&str) -> Result<String, AgentError> + Send + Sync + 'static,