Skip to main content

Tool

Trait Tool 

Source
pub trait Tool {
    // Required methods
    fn info(&self) -> &ToolInfo;
    fn call<'life0, 'async_trait>(
        &'life0 self,
        ctx: AgentContext,
        args: AgentValue,
    ) -> Pin<Box<dyn Future<Output = Result<AgentValue, AgentError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for implementing callable tools.

Tools are functions that can be invoked by LLMs during conversations. Implement this trait to create custom tools that can be registered with the global tool registry.

§Example

use modular_agent_core::{Tool, ToolInfo, AgentContext, AgentValue, AgentError, async_trait};

struct MyTool {
    info: ToolInfo,
}

#[async_trait]
impl Tool for MyTool {
    fn info(&self) -> &ToolInfo {
        &self.info
    }

    async fn call(&self, ctx: AgentContext, args: AgentValue) -> Result<AgentValue, AgentError> {
        // Tool implementation
        Ok(AgentValue::string("result"))
    }
}

Required Methods§

Source

fn info(&self) -> &ToolInfo

Returns metadata about this tool.

Source

fn call<'life0, 'async_trait>( &'life0 self, ctx: AgentContext, args: AgentValue, ) -> Pin<Box<dyn Future<Output = Result<AgentValue, AgentError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Invokes the tool with the given context and arguments.

§Arguments
  • ctx - The agent context for this invocation
  • args - Arguments passed to the tool (typically from LLM)
§Returns

The tool’s result as an AgentValue, or an error if the call fails.

Implementors§