Skip to main content

Tool

Trait Tool 

Source
pub trait Tool: Send + Sync {
    // Required methods
    fn meta(&self) -> &ToolMeta;
    fn invoke(&self, call: &ToolCall) -> Result<ToolOutcome, AxError>;

    // Provided methods
    fn subject(&self, _call: &ToolCall) -> Result<GateSubject, AxError> { ... }
    fn effect_of(&self, _call: &ToolCall) -> Result<Effect, AxError> { ... }
    fn writes(&self, _call: &ToolCall) -> Writes { ... }
}
Expand description

The tool port. Adapters: runtime L0 three, browser, protocol; second adapter: citysim scripted tools.

Send, because a bench of tools is driven on a pool thread rather than on the thread that built it (crates/sprawling/Spec.lean §8-44). A tool that holds something a thread cannot give up has no place on a bench.

Sync, and invoke takes &self, because the read-only calls at the head of a wave run at the same time (crates/runtime/Spec.lean §8-3), so one tool can be inside invoke on several threads at once. A tool with state of its own keeps that state behind its own lock.

Required Methods§

Source

fn meta(&self) -> &ToolMeta

Source

fn invoke(&self, call: &ToolCall) -> Result<ToolOutcome, AxError>

Fail-closed identity: a call whose name differs from meta().name must return E_INVALID_ARGS, never route silently.

Provided Methods§

Source

fn subject(&self, _call: &ToolCall) -> Result<GateSubject, AxError>

What this call is about, read by the grammar this tool already parses its arguments with.

The default is GateSubject::None rather than an inference: a bench that guessed a subject from an argument name has already been wrong once. None says the tool read the call and it names none; a door then judges it against this machine, never skips it.

§Errors

Refuses arguments this tool cannot read - the same refusal its invoke would produce.

Source

fn effect_of(&self, _call: &ToolCall) -> Result<Effect, AxError>

The effect this one call has, which picks the door it meets.

The default is the registered ToolMeta::effect. A tool whose operations differ in kind overrides it: a governance tool answers Effect::Read for an operation that only reads the rules, so a run can see what it is judged by while every operation that rewrites them still meets the Govern refusal (crates/kernel/spec/Gate.lean D26).

§Errors

Refuses arguments this tool cannot read - the same refusal its invoke would produce.

Source

fn writes(&self, _call: &ToolCall) -> Writes

What this call may have written to the city’s tree once it ran; the default reads the declared effect and nothing more.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§