pub trait Tool: Send + Sync {
Show 13 methods
// Required methods
fn spec(&self) -> ToolSpec;
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn annotations(&self) -> ToolAnnotations { ... }
fn annotations_for(&self, _arguments: &Value) -> ToolAnnotations { ... }
fn source_trust(&self, _arguments: &Value) -> SourceTrust { ... }
fn outbound(&self, _arguments: &Value) -> Outbound { ... }
fn validate(&self, arguments: &Value) -> Result<(), String> { ... }
fn timeout(&self) -> Option<Duration> { ... }
fn access(&self, _arguments: &Value) -> AccessManifest { ... }
fn effects(&self, arguments: &Value) -> CallEffects { ... }
fn concurrent_peers(&self) -> usize { ... }
fn suspends(&self) -> bool { ... }
fn resume_child<'life0, 'life1, 'async_trait>(
&'life0 self,
_child: RunState,
_resolution: Resolution,
_ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
An LLM-callable capability. Only spec and call are required.
Richer per-call semantics (annotations, access, typed effects) are optional methods with conservative defaults, so the simple case stays simple.
Required Methods§
fn spec(&self) -> ToolSpec
fn call<'life0, 'life1, 'async_trait>(
&'life0 self,
arguments: Value,
ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Provided Methods§
fn annotations(&self) -> ToolAnnotations
Sourcefn annotations_for(&self, _arguments: &Value) -> ToolAnnotations
fn annotations_for(&self, _arguments: &Value) -> ToolAnnotations
Annotations for one call. Tools whose effect depends on the arguments
(a shell running ls versus rm) override this; the default is the
tool-wide Tool::annotations.
Tool::annotations must be the worst-case (most restrictive)
value for the tool; this may only relax it for a specific call. The
result is trusted as given by authority checks (and recorded in the
receipt), so it must be correct for those arguments. Concurrent
scheduling always uses Tool::annotations, never this value.
Crash-recovery replay uses this per-call idempotent: a call
declared idempotent for its arguments is re-run, not marked
indeterminate.
Sourcefn source_trust(&self, _arguments: &Value) -> SourceTrust
fn source_trust(&self, _arguments: &Value) -> SourceTrust
Who authored what this call returns. The default is Untrusted; a
tool whose output is the owner’s own (a workspace file, the
kernel’s bookkeeping) returns Trusted. A result may override this
with ToolOutput::with_trust.
Sourcefn outbound(&self, _arguments: &Value) -> Outbound
fn outbound(&self, _arguments: &Value) -> Outbound
What this call carries out of the machine if it only reads. The default says nothing does.
Sourcefn validate(&self, arguments: &Value) -> Result<(), String>
fn validate(&self, arguments: &Value) -> Result<(), String>
Deterministic argument checks, run before any policy or I/O. The
kernel checks the arguments against the declared schema
(check_arguments: required keys, types, enums, nested objects
and array items) before calling this, whatever a tool does here, so
an override only adds checks. The default is that schema check.
Sourcefn timeout(&self) -> Option<Duration>
fn timeout(&self) -> Option<Duration>
How long this tool may run, overriding Limits::tool_timeout. Tools
that take their own timeout argument (such as a shell) return a value
at least as long as their own maximum.
Sourcefn access(&self, _arguments: &Value) -> AccessManifest
fn access(&self, _arguments: &Value) -> AccessManifest
Declare what this call will touch. Optional; policies treat an empty manifest as undeclared.
Sourcefn effects(&self, arguments: &Value) -> CallEffects
fn effects(&self, arguments: &Value) -> CallEffects
The typed effects of this call (effect class and normalized target).
The default is CallEffects::none for a call that is read-only and
not egress (per Tool::annotations_for). Otherwise it is what the
call’s declared Tool::access implies (CallEffects::from_access:
a written path is a write effect, a host an egress effect), so an
owner’s denial of the call binds the rest of the run; and
CallEffects::unknown when it declares no access: a read from
another host still sends the request off the machine, so a tool
annotated egress should declare its host or its
EffectKey::egress target. Recomputed
after a hook rewrites the arguments.
Sourcefn concurrent_peers(&self) -> usize
fn concurrent_peers(&self) -> usize
How many calls of this tool may run together in one batch although the tool is not read-only: 0 (the default) runs each call alone. A tool returns more only when it coordinates the shared state its concurrent calls touch itself (sub-agents whose writes a coordination ledger arbitrates). Calls queued this way still run after every earlier call in the batch has been judged, and before any later call that is not concurrent-safe.
Sourcefn suspends(&self) -> bool
fn suspends(&self) -> bool
Whether this tool may answer with ToolOutput::suspended. A call
of such a tool always runs alone, because a run pauses on one call at
a time.
Sourcefn resume_child<'life0, 'life1, 'async_trait>(
&'life0 self,
_child: RunState,
_resolution: Resolution,
_ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn resume_child<'life0, 'life1, 'async_trait>(
&'life0 self,
_child: RunState,
_resolution: Resolution,
_ctx: &'life1 ToolContext,
) -> Pin<Box<dyn Future<Output = ToolResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Continue the child run this tool suspended, with the answer to its
interruption, and return what Tool::call would have returned: a
result, or ToolOutput::suspended if the child paused again.
ctx is that of the delegating run as it is now, so its authority
and declines are the ones to apply: a resumed child answers to them
exactly as a child started by Tool::call does. child may come
from another process.
A crash while this runs leaves the delegating call started with no
result, the same as a crash during Tool::call: on recovery it is
re-run if idempotent and marked indeterminate otherwise.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".