pub trait Tool: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn schema(&self) -> Value;
fn call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 Value,
ctx: &'life2 ToolContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<Content>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
// Provided methods
fn timeout_ms(&self) -> Option<u64> { ... }
fn call_timeout_ms(&self, _args: &Value) -> Option<u64> { ... }
fn metadata(&self) -> ToolMetadata { ... }
fn exposure(&self) -> ToolExposure { ... }
fn should_activate(&self, _ctx: &ActivationContext) -> bool { ... }
}Required Methods§
fn name(&self) -> &'static str
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
Human-readable description of what this tool does and when to use it.
Sourcefn schema(&self) -> Value
fn schema(&self) -> Value
JSON Schema for the tool’s input arguments (MCP inputSchema shape,
without the provider envelope).
fn call<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
args: &'life1 Value,
ctx: &'life2 ToolContext,
) -> Pin<Box<dyn Future<Output = AgentResult<Vec<Content>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Provided Methods§
Sourcefn timeout_ms(&self) -> Option<u64>
fn timeout_ms(&self) -> Option<u64>
Timeout for this tool in milliseconds.
Returns Some(ms) to enforce a timeout, or None to use the
framework’s default timeout from ToolConfig.default_tool_timeout_ms.
Tools that need more or less time should override this method.
Sourcefn call_timeout_ms(&self, _args: &Value) -> Option<u64>
fn call_timeout_ms(&self, _args: &Value) -> Option<u64>
Execution budget for a specific call, derived from its args.
The pipeline watchdog consults this before arming: Some(ms) overrides
Tool::timeout_ms for this invocation, and Some(0) means unbounded
(no watchdog — the tool enforces its own limits, or the call is
fire-and-forget). None falls back to Tool::timeout_ms / config.
Tools whose arguments carry a per-call timeout (e.g. timeout_ms)
MUST surface it here. Otherwise the pipeline arms its own watchdog
from the tool-level default and can kill a call that the tool was
explicitly promised more time for (session 20261018_7844215b: a
660s execute_command budget was cut at the 600s framework default).
Sourcefn metadata(&self) -> ToolMetadata
fn metadata(&self) -> ToolMetadata
Machine-readable metadata for tool introspection.
The default implementation derives name and description from
Tool::name and Tool::description, sets origin to "custom",
and leaves requirements empty. Tool authors are encouraged to
override this to provide an accurate origin and version.
Sourcefn exposure(&self) -> ToolExposure
fn exposure(&self) -> ToolExposure
Visibility level for this tool. Default: Direct (always visible).
Override to return Deferred (conditionally visible) or Hidden
(never visible to the model). Deferred tools are only included
when Tool::should_activate returns true.
Sourcefn should_activate(&self, _ctx: &ActivationContext) -> bool
fn should_activate(&self, _ctx: &ActivationContext) -> bool
Activation condition for Deferred tools.
Called once per turn for each Deferred tool. Return true to
include this tool in the model’s tool list this turn. Ignored for
Direct and Hidden tools.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".