Skip to main content

TypedAgentTool

Trait TypedAgentTool 

Source
pub trait TypedAgentTool:
    Send
    + Sync
    + 'static {
    type Args: DeserializeOwned + JsonSchema + Send + 'static;

    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        call_id: &'life1 str,
        args: Self::Args,
        signal: CancellationToken,
        update: ToolUpdateSink,
    ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided methods
    fn requires_exclusive_sandbox(&self) -> bool { ... }
    fn max_result_chars(&self) -> Option<usize> { ... }
    fn history_policy(&self) -> ToolHistoryPolicy { ... }
    fn identity_policy(&self) -> ToolIdentityPolicy { ... }
    fn aborts_siblings_on_error(&self) -> bool { ... }
    fn counts_toward_tool_call_limit(&self) -> bool { ... }
    fn parallel_safe_per_turn(&self) -> bool { ... }
    fn counts_toward_termination_vote(&self) -> bool { ... }
    fn prepare_arguments(&self, args: Value) -> Value { ... }
}
Expand description

Implement this for tools whose argument shape is a typed Rust struct/enum. The blanket AgentTool impl below derives parameters_schema from Args via schemars and centralizes the Value → Args parse path. New tools should implement TypedAgentTool, not AgentTool directly; existing tools are migrated incrementally.

Required Associated Types§

Source

type Args: DeserializeOwned + JsonSchema + Send + 'static

The argument shape. The wire schema is generated from this type; the dispatcher parses incoming Value into Args once and hands the typed value to run.

Required Methods§

Source

fn name(&self) -> &str

Source

fn description(&self) -> &str

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, call_id: &'life1 str, args: Self::Args, signal: CancellationToken, update: ToolUpdateSink, ) -> Pin<Box<dyn Future<Output = Result<ToolResult, ToolError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Execute the tool with already-parsed typed args.

Provided Methods§

Source

fn requires_exclusive_sandbox(&self) -> bool

Whether this tool needs exclusive sandbox access. Default false.

Source

fn max_result_chars(&self) -> Option<usize>

Per-tool max-result-chars override for ToolResultBudget. Default None (use the global default).

Source

fn history_policy(&self) -> ToolHistoryPolicy

Tool-owned hints for history transforms. Defaults to no special handling.

Source

fn identity_policy(&self) -> ToolIdentityPolicy

Tool-owned identity declaration for loop-detection plugins. Mirrors AgentTool::identity_policy; defaults to “single opaque operation”. See clark_agent::tool_identity.

Source

fn aborts_siblings_on_error(&self) -> bool

Whether a non-fatal failure of this tool in a parallel batch cancels still-running siblings. Default false.

Source

fn counts_toward_tool_call_limit(&self) -> bool

Whether this tool consumes a slot from LoopConfig::max_tool_calls_per_turn. Default true.

Source

fn parallel_safe_per_turn(&self) -> bool

Whether this tool is safe to invoke multiple times in a single assistant turn alongside other tool calls. Default false. See the corresponding AgentTool::parallel_safe_per_turn docstring.

Source

fn counts_toward_termination_vote(&self) -> bool

Whether this tool’s terminate vote counts in the unanimous-vote tally. Default true. Status-only progress tools opt out by returning false; see the corresponding AgentTool::counts_toward_termination_vote docstring.

Source

fn prepare_arguments(&self, args: Value) -> Value

Optional pre-deserialization normalization of raw args. Pure function. Runs before strip_top_level_nulls and coerce_string_scalars_at_top_level so tool-specific canonicalization (e.g. inferring a tagged-enum’s action discriminator from variant-unique fields) lands first.

Default: identity. See AgentTool::prepare_arguments.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§