pub trait Tool: Send + Sync {
type Args: DeserializeOwned + JsonSchema + Send;
type Output: Serialize + ToolOutput + Send;
// Required methods
fn kind(&self) -> ToolKind;
fn description(&self) -> &str;
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
args: Self::Args,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, ToolError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait;
// Provided methods
fn parameters_schema(&self) -> Value { ... }
fn input_format(&self) -> ToolInputFormat { ... }
}Expand description
A tool authored against concrete types; the wire schema is derived from
Tool::Args, never hand-written (ADR-0003).
The tool has no name of its own — its model-facing wire name is assigned by
the harness pack when it registers the tool into a crate::Registry
(ADR-0006/0012). Author tools with concrete Args/Output types; the registry
erases them to Box<dyn DynTool> at its boundary.
Required Associated Types§
Sourcetype Args: DeserializeOwned + JsonSchema + Send
type Args: DeserializeOwned + JsonSchema + Send
The deserializable, schema-deriving argument type the model must supply.
Sourcetype Output: Serialize + ToolOutput + Send
type Output: Serialize + ToolOutput + Send
The structured output; also rendered to model-facing text via ToolOutput.
Required Methods§
Sourcefn description(&self) -> &str
fn description(&self) -> &str
A human-readable description offered to the model alongside the schema.
Sourcefn run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
args: Self::Args,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn run<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: &'life1 ToolCtx,
args: Self::Args,
) -> Pin<Box<dyn Future<Output = Result<Self::Output, ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Execute the call.
§Errors
Returns ToolError::Respond for any recoverable failure (the model
retries) and ToolError::Fatal only when the transcript is
unrecoverable (ADR-0004).
Provided Methods§
Sourcefn parameters_schema(&self) -> Value
fn parameters_schema(&self) -> Value
The JSON Schema for Tool::Args, derived via schemars (ADR-0003).
The default derives it from the type and should rarely be overridden.
Subschemas are inlined (no $defs/$ref) so every wire can ship the
schema as a self-contained input_schema — Grok Build generates tool
schemas the same way (registry/types.rs generate_schema,
inline_subschemas = true). Flat Args structs are unaffected; this
guards future enum/nested args.
Sourcefn input_format(&self) -> ToolInputFormat
fn input_format(&self) -> ToolInputFormat
How the tool’s input is specified to the model. Defaults to the derived
JSON schema (every tool today); a freeform tool (codex apply_patch)
overrides with ToolInputFormat::Freeform and takes raw-text args
(Args decodable from a JSON string).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".