Skip to main content

ToolRegistry

Struct ToolRegistry 

Source
pub struct ToolRegistry { /* private fields */ }
Expand description

Registry of tools available to an agent.

Stores tools in a HashMap for O(1) lookup by name and supports aliases (e.g., "bash_exec" → "exec") that are resolved transparently but not exposed in definitions() or list().

Implementations§

Source§

impl ToolRegistry

Source

pub fn new() -> Self

Create an empty tool registry.

Source

pub fn set_gate(&mut self, gate: Arc<dyn ToolGate>)

Check every call with gate before it runs. Clones of the registry keep it.

Source

pub fn gate(&self) -> Option<&Arc<dyn ToolGate>>

The gate calls pass, if any.

Source

pub fn set_truncate_on_overflow(&mut self, enabled: bool)

When true, oversized output is truncated and dropped. Default: false (the full output is saved to a temp file and the agent gets a truncated preview with the file’s path). Those files are deleted when the registry and all its clones are dropped.

Source

pub fn register(&mut self, tool: Arc<dyn Tool>)

Register a tool (replaces existing tool with same name).

Source

pub fn remove(&mut self, name: &str) -> bool

Remove a tool by name. Returns true if the tool was present.

Source

pub fn strip_prefixes(&mut self, prefixes: &[&str])

Remove every tool whose name starts with one of prefixes. Aliases pointing at removed tools are also dropped.

Source

pub fn alias(&mut self, alias: &str, target: &str)

Register an alias so that lookups for alias resolve to target. Aliases are not exposed in definitions() or list().

Source

pub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>

Look up a tool by name (checks aliases if direct lookup fails). Always resolves any registered tool, even if not in the active set.

Source

pub fn contains(&self, name: &str) -> bool

Returns true if a tool with the given name is registered (without logging).

Source

pub fn retain(&mut self, f: impl FnMut(&str) -> bool)

Keep only tools whose name satisfies the predicate.

Source

pub fn list(&self) -> Vec<&str>

List all registered tool names (sorted).

Source

pub fn list_with_descriptions(&self) -> Vec<(&str, &str)>

List all registered tools with their names and descriptions (sorted by name).

Source

pub async fn execute( &self, call: &ToolCall, working_dir: Option<&PathBuf>, cancel_token: &CancellationToken, ) -> ToolResult

Execute a tool call from the LLM.

Looks up the tool by name, builds a ToolContext, and runs it. Returns a ToolResult::Failure if the tool is not found or if execution errors. If the tool defines timeout_secs, the call is wrapped in a timeout. Tools without a timeout are cancelled immediately when cancel_token fires.

Source

pub async fn execute_with_progress( &self, call: &ToolCall, working_dir: Option<&PathBuf>, cancel_token: &CancellationToken, progress_tx: UnboundedSender<String>, ) -> ToolResult

Like Self::execute but attaches a progress channel so tools can stream incremental output (e.g. stdout lines from bash).

Source

pub async fn execute_in_context( &self, call: &ToolCall, ctx: ToolContext<'_>, ) -> ToolResult

Execute with parent configuration and optional progress reporting.

Source

pub fn is_concurrent(&self, call: &ToolCall) -> bool

Whether call may run alongside other calls. Unknown tools fail at once, so they count as concurrent.

Source

pub fn supports_background(&self, call: &ToolCall) -> bool

Source

pub fn humanize(&self, call: &ToolCall) -> String

Human-readable summary of a tool call’s arguments.

Source

pub fn definitions(&self) -> Vec<ToolDefinition>

Generate LLM tool definitions for all registered tools.

Trait Implementations§

Source§

impl Clone for ToolRegistry

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ToolRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more