pub trait Tool: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn description(&self) -> &str;
fn parameters_schema(&self) -> Value;
fn invoke<'life0, 'async_trait>(
&'life0 self,
arguments: Value,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
// Provided method
fn invoke_in_context<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_ctx: &'life1 FunctionInvocationContext,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
}Expand description
An executable tool the framework can invoke locally.
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
A human/model-readable description.
Sourcefn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
The JSON Schema describing the tool’s parameters.
Provided Methods§
Sourcefn invoke_in_context<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_ctx: &'life1 FunctionInvocationContext,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn invoke_in_context<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
_ctx: &'life1 FunctionInvocationContext,
) -> Pin<Box<dyn Future<Output = Result<Value, Error>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Execute the tool with access to the surrounding
FunctionInvocationContext
(the agent session, middleware metadata, …).
The function-invocation loop calls this method; the default
implementation ignores the context and delegates to Tool::invoke,
so ordinary tools need not care. Override it for tools that read the
invocation context — the Rust analogue of an upstream FunctionTool
whose function declares a ctx: FunctionInvocationContext parameter
(e.g. the Agent::as_tool wrapper, which forwards ctx.session to
the sub-agent when propagate_session is enabled).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".