pub trait Tool: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn parameters(&self) -> Value;
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: ToolContext<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn timeout_secs(&self) -> Option<u64> { ... }
fn max_output_bytes(&self) -> usize { ... }
fn max_output_lines(&self) -> usize { ... }
fn concurrent(&self) -> bool { ... }
fn supports_background(&self) -> bool { ... }
fn humanize(&self, args: &Value) -> String { ... }
}Expand description
Trait for tools that can be invoked by the agent.
Implementations define a name, description, JSON schema parameters, and async execution
logic. Tools are registered in a ToolRegistry and become available to the LLM during
conversation turns via function calling.
§Required methods
name— unique identifier used by the LLM to invoke the tooldescription— shown to the LLM to decide when to call the toolparameters— JSON Schema object describing expected argumentsexecute— async logic that runs when the tool is called
§Optional overrides
humanize— display-friendly summary (default: comma-separated arg keys)timeout_secs— per-tool timeout (default: uses global default)max_output_bytes— output size limit (default: 256 KiB)max_output_lines— output line count limit (default: 10,000)
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Unique tool name (used for invocation). Must match the name the LLM sees in its function definitions.
Sourcefn description(&self) -> &str
fn description(&self) -> &str
Human-readable description for the LLM. Used to help the model decide when to invoke this tool.
Sourcefn parameters(&self) -> Value
fn parameters(&self) -> Value
JSON Schema object describing the tool’s parameters.
Sourcefn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: ToolContext<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: ToolContext<'life1>,
) -> Pin<Box<dyn Future<Output = Result<ToolResult>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Execute the tool with given arguments. Returns a ToolResult on success.
Provided Methods§
Sourcefn timeout_secs(&self) -> Option<u64>
fn timeout_secs(&self) -> Option<u64>
Optional per-tool timeout in seconds. Returns None to use the global default.
Sourcefn max_output_bytes(&self) -> usize
fn max_output_bytes(&self) -> usize
Maximum allowed output size in bytes. Tools that produce large payloads
(e.g. base64-encoded images, arbitrary MCP responses) should return
usize::MAX to bypass the limit.
Sourcefn max_output_lines(&self) -> usize
fn max_output_lines(&self) -> usize
Maximum allowed output line count. Tools that produce large payloads
should return usize::MAX to bypass the limit.
Sourcefn concurrent(&self) -> bool
fn concurrent(&self) -> bool
Whether this tool may run at the same time as other tools from the
same model reply, when the agent allows parallel tool calls. Return
false for tools that share state or act on one device, so they run
alone between concurrent batches.
Sourcefn supports_background(&self) -> bool
fn supports_background(&self) -> bool
Whether a running call can continue as a managed background task.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".