pub trait Tool: Send + Sync {
// Required methods
fn schema(&self) -> &ToolSchema;
fn safety_hint(&self, args: &Value) -> SafetyClass;
fn describe<'a>(
&'a self,
args: &'a Value,
ctx: ToolContext<'a>,
) -> BoxFuture<'a, ToolCallDescription>;
fn execute(&self, args: Value, ctx: ToolContext<'_>) -> ToolStream;
}Expand description
Tools callable by the agent.
Implementors are typically stateless (each invocation receives all dependencies via
args + ToolContext); if you need to hold state such as connections or caches,
place the state on Self and register an Arc<Self> with the main loop.
Required Methods§
Sourcefn schema(&self) -> &ToolSchema
fn schema(&self) -> &ToolSchema
Tool metadata. Returns a reference to avoid allocating on every call.
Sourcefn safety_hint(&self, args: &Value) -> SafetyClass
fn safety_hint(&self, args: &Value) -> SafetyClass
Provides a safety-level hint to the sandbox policy without actually executing the tool.
args is the already-deserialized JSON value — the same tool’s safety level may
vary by arguments (e.g., the bash tool escalates to SafetyClass::Destructive
when command contains rm). The implementation should be a pure function
and perform no IO.
Sourcefn describe<'a>(
&'a self,
args: &'a Value,
ctx: ToolContext<'a>,
) -> BoxFuture<'a, ToolCallDescription>
fn describe<'a>( &'a self, args: &'a Value, ctx: ToolContext<'a>, ) -> BoxFuture<'a, ToolCallDescription>
Generates a “self-description” before execution, for display to the ACP client.
The async signature and ToolContext injection allow implementations to perform
lightweight IO during the describe phase (typical example: write_file reads the
old content before requesting authorization, producing a precise old↔new diff for
the client—more reviewable than “entirely new content”).
Performance constraint: describe runs before every ACP ToolCall push.
Implementations should remain fast and graceful on failure (on IO failure, degrade
to returning basic fields; do not let describe itself throw—the signature
provides no error channel).
See the field conventions on ToolCallDescription for which fields are filled
by whom.
Sourcefn execute(&self, args: Value, ctx: ToolContext<'_>) -> ToolStream
fn execute(&self, args: Value, ctx: ToolContext<'_>) -> ToolStream
Initiates a tool call and returns an event stream.
See ToolEvent for the stream elements. The stream must end immediately after
the terminal event. Dropping the stream is treated as cancellation (equivalent to
ctx.cancel.cancel()).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".