pub trait Tool: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn parameters_schema(&self) -> Value;
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 mut AgentContext,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn is_system(&self) -> bool { ... }
fn is_read_only(&self) -> bool { ... }
fn execute_readonly<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn to_def(&self) -> ToolDef { ... }
}Expand description
A tool that an agent can invoke.
Implement this trait for each capability you want to expose to the LLM agent.
Tools are registered in a ToolRegistry and dispatched by the agent loop.
Read-only tools (is_read_only() -> true) can execute in parallel.
Write tools execute sequentially with exclusive &mut AgentContext.
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Human-readable description shown to the LLM.
Sourcefn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
JSON Schema for the tool’s parameters (generated via json_schema_for::<Args>()).
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 mut AgentContext,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Provided Methods§
Sourcefn is_system(&self) -> bool
fn is_system(&self) -> bool
System tools are always visible (not subject to progressive discovery).
Sourcefn is_read_only(&self) -> bool
fn is_read_only(&self) -> bool
Read-only tools can execute in parallel via execute_readonly.
Sourcefn execute_readonly<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute_readonly<'life0, 'life1, 'async_trait>(
&'life0 self,
args: Value,
ctx: &'life1 AgentContext,
) -> Pin<Box<dyn Future<Output = Result<ToolOutput, ToolError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute without mutable context (for parallel read-only dispatch).
Default: delegates to execute with a cloned context. Override for true
read-only tools to avoid the clone.